Skip to content

Commit

Permalink
Fix #11569: Core JS setGlobalLocaleValue
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Mar 10, 2024
1 parent c680199 commit 5127508
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/14_0_0/core/localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ if (window.PrimeFaces) {

```

### Overwrite Global Value

In certain situations, you might find it necessary to unify all locales to a single value. For instance, if you wish to establish `firstDayOfWeek=1` uniformly across all locales.
The function `setGlobalLocaleValue` is available for precisely this purpose, ensuring consistency by applying the same value across all locales. Example usage:

```js
PrimeFaces.setGlobalLocaleValue('firstDayOfWeek', 1);
```

### Usage

To add another locale to the API, first create the locale object first with settings and assign it as a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,35 @@
var locale = this.getLocaleSettings();
return (locale&&locale[key]) ? locale[key] : PrimeFaces.locales['en_US'][key];
},

/**
* Loop over all locales and set the label to the new value in all locales.
* @param {string} localeKey The locale key
* @param {string} localeValue The locale value
*/
setGlobalLocaleValue: function(localeKey, localeValue) {
// Recursive function to iterate over nested objects
function iterateLocale(locale, lkey, lvalue) {
for (var key in locale) {
if (typeof locale[key] === 'object') {
// If the value is an object, call the function recursively
iterateLocale(locale[key], lkey, lvalue);
} else {
// Otherwise, set the new value if found
if (key === lkey) {
locale[key] = lvalue;
}
}
}
}

// iterate over all locales and try and set the key in each locale
for (var lang in PrimeFaces.locales) {
if (typeof PrimeFaces.locales[lang] === 'object') {
iterateLocale(PrimeFaces.locales[lang], localeKey, localeValue)
}
}
},

/**
* For 4.0 jQuery deprecated $.trim in favor of PrimeFaces.trim however that does not handle
Expand Down

0 comments on commit 5127508

Please sign in to comment.