turbogui-angular 19.0.0 → 19.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1777,18 +1777,19 @@ class LocalesBaseService {
1777
1777
  return this._missingKeyFormat;
1778
1778
  }
1779
1779
  /**
1780
- * Initializes the translation system by loading and parsing bundle files from the specified JSON object.
1781
- * After the method finishes, the class will contain all the translation data and will be ready to translate any provided key.
1780
+ * Adds translations to the class by loading and parsing bundles from the provided JSON object.
1781
+ * After the method finishes, the class will contain all the translation data and will be ready to translate
1782
+ * any provided key to any of the specified locales.
1782
1783
  *
1783
- * @param translations A JSON object containing the translation data. The structure must be as follows:
1784
- * { library_name: { bundle_name: { locale_code: { key1: "translation1", key2: "translation2" } } } ... }
1784
+ * @param locales An array of locale codes (e.g., ['en_US', 'es_ES', 'fr_FR']) to load from the json data into this class.
1785
+ * The order of this array will determine the priority when looking for translations.
1785
1786
  *
1786
- * @param locales An array of locale codes (e.g., ['en_US', 'es_ES', 'fr_FR']) to load into this class. The order of this array
1787
- * will determine the translation priority
1787
+ * @param json A JSON object containing the translation data. The structure must be as follows:
1788
+ * { library_name: { bundle_name: { locale_code: { key1: "translation1", key2: "translation2" } } } ... }
1788
1789
  *
1789
1790
  * @return True if the translations get correctly loaded. Any unsuccessful initialization will throw an exception
1790
1791
  */
1791
- initializeFromJson(translations, locales) {
1792
+ loadLocalesFromJson(locales, json) {
1792
1793
  this._isInitialized = false;
1793
1794
  // Validate received locales are correct
1794
1795
  for (const locale of locales) {
@@ -1796,9 +1797,9 @@ class LocalesBaseService {
1796
1797
  }
1797
1798
  // Validate the translations object follows the right structure
1798
1799
  let isTranslationsValid = false;
1799
- for (const library in translations) {
1800
- for (const bundle in translations[library]) {
1801
- for (const locale in translations[library][bundle]) {
1800
+ for (const library in json) {
1801
+ for (const bundle in json[library]) {
1802
+ for (const locale in json[library][bundle]) {
1802
1803
  this._validateLocaleString(locale);
1803
1804
  isTranslationsValid = true;
1804
1805
  }
@@ -1807,39 +1808,38 @@ class LocalesBaseService {
1807
1808
  if (!isTranslationsValid) {
1808
1809
  throw new Error('translations must be a non empty object with the structure: { library: { bundle: { xx_XX: { key: translation } } } }');
1809
1810
  }
1810
- this._loadedTranslations = translations;
1811
+ this._loadedTranslations = json;
1811
1812
  this._locales = locales;
1812
1813
  this._languages = locales.map((l) => l.substring(0, 2));
1813
1814
  this._cacheHashBaseString = this._wildCardsFormat + this._missingKeyFormat + this._locales[0];
1814
- return this._isInitialized = true;
1815
+ this._isInitialized = true;
1816
+ return true;
1815
1817
  }
1816
1818
  /**
1817
1819
  * Initializes the translation system by loading and parsing bundle files from the specified translations path.
1818
1820
  * After the promise finishes, the class will contain all the translation data and will be ready to translate any
1819
1821
  * provided key.
1820
1822
  *
1821
- * @param translationsPath - Url where the translations Json structure of libraries/bundles/locales/keys is available.
1822
- * @param locales An array of locale codes (e.g., ['en_US', 'es_ES', 'fr_FR']) to load. These will be added to the translation
1823
- * path using the following format: translationsPath/en_US-es_ES-fr_FR. The order of this array will determine the
1824
- * translation priority
1825
- * @param parameters Any extra parameters to be attached to the translationsPath after the locales like /param1/param2/ etc
1823
+ * @param locales An array of locale codes (['en_US', 'es_ES', 'fr_FR', ...]) to load from the url response.
1824
+ * The order of this array will determine the translation priority
1825
+ * @param url - Url where the translations are found. The response must be a Json with the expected structure:
1826
+ * { library_name: { bundle_name: { locale_code: { key1: "translation1", key2: "translation2" } } } ... }
1826
1827
  *
1827
1828
  * @return A promise that will resolve if the translations get correctly loaded, or reject with an error if load fails
1828
1829
  */
1829
- initializeFromUrl(translationsPath, locales, parameters) {
1830
+ loadLocalesFromUrl(locales, url) {
1830
1831
  this._isInitialized = false;
1831
- const translationsFullPath = translationsPath + '/' + locales.join('-') + '/' + parameters.join('/');
1832
1832
  return new Promise((resolve, reject) => {
1833
- fetch(translationsFullPath).then(response => {
1833
+ fetch(url).then(response => {
1834
1834
  if (!response.ok) {
1835
1835
  throw new Error(`HTTP error! status: ${response.status}`);
1836
1836
  }
1837
1837
  return response.json();
1838
1838
  }).then(data => {
1839
- this.initializeFromJson(data, locales);
1839
+ this.loadLocalesFromJson(locales, data);
1840
1840
  resolve(undefined);
1841
1841
  }).catch(error => {
1842
- reject(new Error(`ERROR LOADING LOCALES FROM: ${translationsFullPath}\n` + error));
1842
+ reject(new Error(`ERROR LOADING LOCALES FROM: ${url}\n` + error));
1843
1843
  });
1844
1844
  });
1845
1845
  }