There are many ways to deal with this.
As Felix mentions you can use fragments to attach resource properties to a bundle.
If you want more centralized resource properties (for example, one bundle holds all the l10n for an application), then each bundle will need to know how to locate the proper bundle. That bundle could register a ResourceBunde service for your application which has a service property describing the l10n the bundle contains.
Dictionary<String,Sting> props = new Hashtable<>();
props.put("basename", "foo");
props.put("locale", "en_US");
context.registerService(ResourceBundle.class, new ServiceFactory<ResourceBundle>() {
ResourceBundle getService(...) {
return ResourceBundle.getBundle("foo", "en_US");
}
}, props);
You can then find the service for the ResourceBundle you need.
ref = context.getServiceReference(ResourceBundle.class, "(&(basename="+basename+")(locale="+loggedInUsersLocale+"))"
ResourceBundle bundle = ref.getService();
--
BJ Hargrave
Senior Technical Staff Member, IBM // office: +1 386 848 1781
OSGi Fellow and CTO of the OSGi Alliance // mobile: +1 386 848 3788
hargr...@us.ibm.com
BJ Hargrave
Senior Technical Staff Member, IBM // office: +1 386 848 1781
OSGi Fellow and CTO of the OSGi Alliance // mobile: +1 386 848 3788
hargr...@us.ibm.com
----- Original message -----
From: Felix Meschberger <fmesc...@adobe.com>
Sent by: osgi-dev-boun...@mail.osgi.org
To: OSGi Developers List <osgi-dev@mail.osgi.org>
Cc:
Subject: Re: [osgi-dev] I18N ?
Date: Mon, Jan 16, 2017 11:03 AM
Hi
IIRC Eclipse does it with language fragments.
Regards
Felix
> Am 16.01.2017 um 16:42 schrieb Tim Ward <t...@telensa.com>:
>
> What's the recommended approach to loading strings for I18N?
>
> Without using OSGi, one might create a bunch of .properties files, and load them as needed with
>
> ResourceBundle.getBundle( "basename", loggedInUsersLocale )
>
> with the basename[_...].properties files on the class path. With a suitably chosen class path one can then drop in .properties files at run time to add new language translations[#].
>
> When using OSGi, dropping files into "the class path" is obviously somewhat more complicated, and in any case it would be more in keeping to drop in bundles rather than raw .properties files, wouldn't it?
>
> What are the common patterns for doing this with OSGi? - the specific requirement here seems to be to add a new language without a system rebuild: putting a bunch of .properties files into an I18N bundle which gets rebuilt for new languages (ie rebuilding a bundle not the entire system) would probably work but off the top of my head sounds less attractive than a pattern which involves dropping in a new bundle for a new language. Or should I be looking at the fileinstall service? (So many ways to approach things ...)
>
> [#] give or take the caching, which I haven't experimented with yet
>
> --
> Tim Ward
>
> _______________________________________________
> OSGi Developer Mail List
> osgi-dev@mail.osgi.org
> https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________ OSGi Developer Mail List osgi-dev@mail.osgi.org https://mail.osgi.org/mailman/listinfo/osgi-dev