Skip to content

Commit

Permalink
Lib i18n must allow to specify application to read resources #10417
Browse files Browse the repository at this point in the history
  • Loading branch information
anatol-sialitski committed Feb 13, 2024
1 parent c546648 commit dfe1683
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions modules/lib/lib-i18n/src/main/resources/lib/xp/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ export function localize(params: LocalizeParams): string {
*
* @param {string|string[]} locale A string-representation of a locale, or an array of locales in preferred order.
* @param {string[]} bundles List of bundle names. Bundle names are specified as paths, relative to the `src/main/resources` folder.
* @param {string} [application] Application key where to find resource bundles. Defaults to current application.
*
* @returns {object} An object of all phrases.
*
* @example
* i18nLib.getPhrases('en', ['i18n/phrases'])
*/
export function getPhrases(locale: string | string[], bundles: string[]): Record<string, string> {
export function getPhrases(locale: string | string[], bundles: string[], application?: string): Record<string, string> {
const bean = __.newBean<LocaleScriptBean>('com.enonic.xp.lib.i18n.LocaleScriptBean');
bean.setApplication(__.nullOrValue(application));
const locales: string[] = ([] as string[]).concat(locale);
return __.toNativeObject(bean.getPhrases(locales, bundles));
}
Expand All @@ -87,10 +89,12 @@ export function getPhrases(locale: string | string[], bundles: string[]): Record
* This function returns the list of supported locale codes for the specified bundles.
*
* @param {string[]} bundles List of bundle names.
* @param {string} application Application key where to find resource bundles. Defaults to current application.
*
* @returns {string[]} A list of supported locale codes for the specified bundles.
*/
export function getSupportedLocales(bundles: string[]): string[] {
export function getSupportedLocales(bundles: string[], application?: string): string[] {
const bean = __.newBean<LocaleScriptBean>('com.enonic.xp.lib.i18n.LocaleScriptBean');
bean.setApplication(__.nullOrValue(application));
return __.toNativeObject(bean.getSupportedLocales(bundles));
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports.testGetPhrases = function () {
'b': '2'
};

var result = i18n.getPhrases('en', null);
var result = i18n.getPhrases('en', null, 'com.enonic.myapplication');
t.assertJsonEquals(actual, result);
};

Expand Down

0 comments on commit dfe1683

Please sign in to comment.