Forums de discussion

Override Liferay module localization key value

thumbnail
Jignesh Vachhani, modifié il y a 7 années.

Override Liferay module localization key value

Liferay Master Publications: 803 Date d'inscription: 10/03/08 Publications récentes
I want to override Liferay existing locales properties by giving multiple language.id properties :

@Component(
immediate = true,
property = {
"language.id=ar_SA",
"language.id=de_DE",
"language.id=en_US",
"language.id=es_US",
"language.id=fr_CA",
"language.id=fr_FR",
"language.id=it_IT",
"language.id=ja_JP",
"language.id=nl_NL",
"language.id=pl_PL",
"language.id=pt_BR",
"language.id=ru_RU",
"language.id=tr_TR",
"language.id=zh_CN"
},
service = ResourceBundle.class
)
public class ResourceBundleLoaderComponent extends ResourceBundle {
}
Can I write This with multiple language.id properties ? or i will have to define individual class for each language.id ?
thumbnail
ANKIT SRIVASTAVA, modifié il y a 7 années.

RE: Override Liferay module localization key value

Junior Member Publications: 76 Date d'inscription: 02/02/11 Publications récentes
Is it working for you? I tried defining multiple language.id in property but it does not work.

It seems, we need to create individual class for each locale.emoticon

Thanks,
Ankit
thumbnail
Jignesh Vachhani, modifié il y a 7 années.

RE: Override Liferay module localization key value

Liferay Master Publications: 803 Date d'inscription: 10/03/08 Publications récentes
ANKIT SRIVASTAVA:
Is it working for you? I tried defining multiple language.id in property but it does not work.

It seems, we need to create individual class for each locale.emoticon

Thanks,
Ankit



Need to confirm with Liferay team.
thumbnail
Christoph Rabel, modifié il y a 6 années.

RE: Override Liferay module localization key value

Liferay Legend Publications: 1554 Date d'inscription: 24/09/09 Publications récentes
Fiddled with it for a while, but I had to create a class per language. I have created a base class to have only a minimal implementation for each language.
Here's the code of my implementation, take care, the example in the Liferay documentation is buggy. It only works for the default language en_US.

Baseclass:

public class ResourceBundleBase extends ResourceBundle {
	@Override
    protected Object handleGetObject(String key) {
        return _resourceBundle.getObject(key);
    }
    @Override
    public Enumeration<string> getKeys() {
        return _resourceBundle.getKeys();
    }
    private final ResourceBundle _resourceBundle = ResourceBundle.getBundle(
    		"content.Language", getLocale(), getClass().getClassLoader(), UTF8Control.INSTANCE);
}
</string>


Example for German Language:

@Component(
	    property = { "language.id=de_DE" }, 
	    service = ResourceBundle.class
	)
public class DeDEResourceBundle extends ResourceBundleBase {
	@Override
	public Locale getLocale() {
		return Locale.GERMANY;
	}
}
thumbnail
Carlos Sierra, modifié il y a 6 années.

RE: Override Liferay module localization key value

Junior Member Publications: 32 Date d'inscription: 21/05/13 Publications récentes
Hello there,

I believe it should be easier if you programatically register the ResourceBundle's to their keys.

If you use a @Component to do that you can get a BundleContext in the @Activate method:


@Component(immediate=true)
public class ResourceBundleRegistrator {

    @Activate
    public void activate(BundleContext bundleContext) {
        getMyResourceBundles();
        for each resource bundle {
            props = set the language id;
            ServiceRegistration&lt;&gt; sr = bundleContext.registerService(ResourceBundle.class, resourceBundle, props);
            store sr;
        }
    }

    @Deactivate
    public void deactivate() {
        for each service registration {
            sr.unregister();
        }
    }

}



with the pseudocode above you should be able to register as many ResourceBundles as you like to augment those of the portal.

Please note that many modules now use another abstraction ResourceBundleLoader that might make it easier for you to
pinpoint a particular module to augment.

You can find more information here

Hope this helps!
thumbnail
Jignesh Vachhani, modifié il y a 6 années.

RE: Override Liferay module localization key value (Réponse)

Liferay Master Publications: 803 Date d'inscription: 10/03/08 Publications récentes
I created separate class for the different language and loaded through resource bundle and it works perfectly for me.