@fkui/i18next-translate 6.11.0 → 6.13.0

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.
package/dist/cjs/index.js CHANGED
@@ -1214,12 +1214,10 @@ class Interpolator {
1214
1214
  clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
1215
1215
  clonedOptions.applyPostProcessor = false;
1216
1216
  delete clonedOptions.defaultValue;
1217
- let doReduce = false;
1218
- if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
1219
- const r = match[1].split(this.formatSeparator).map(elem => elem.trim());
1220
- match[1] = r.shift();
1221
- formatters = r;
1222
- doReduce = true;
1217
+ const keyEndIndex = /{.*}/.test(match[1]) ? match[1].lastIndexOf('}') + 1 : match[1].indexOf(this.formatSeparator);
1218
+ if (keyEndIndex !== -1) {
1219
+ formatters = match[1].slice(keyEndIndex).split(this.formatSeparator).map(elem => elem.trim()).filter(Boolean);
1220
+ match[1] = match[1].slice(0, keyEndIndex);
1223
1221
  }
1224
1222
  value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
1225
1223
  if (value && match[0] === str && !isString(value)) return value;
@@ -1228,7 +1226,7 @@ class Interpolator {
1228
1226
  this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
1229
1227
  value = '';
1230
1228
  }
1231
- if (doReduce) {
1229
+ if (formatters.length) {
1232
1230
  value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
1233
1231
  ...options,
1234
1232
  interpolationkey: match[1].trim()
@@ -2067,8 +2065,16 @@ class I18n extends EventEmitter {
2067
2065
  dir(lng) {
2068
2066
  if (!lng) lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
2069
2067
  if (!lng) return 'rtl';
2068
+ if (Intl.Locale) {
2069
+ const l = new Intl.Locale(lng);
2070
+ if (l && l.getTextInfo) {
2071
+ const ti = l.getTextInfo();
2072
+ if (ti && ti.direction) return ti.direction;
2073
+ }
2074
+ }
2070
2075
  const rtlLngs = ['ar', 'shu', 'sqr', 'ssh', 'xaa', 'yhd', 'yud', 'aao', 'abh', 'abv', 'acm', 'acq', 'acw', 'acx', 'acy', 'adf', 'ads', 'aeb', 'aec', 'afb', 'ajp', 'apc', 'apd', 'arb', 'arq', 'ars', 'ary', 'arz', 'auz', 'avl', 'ayh', 'ayl', 'ayn', 'ayp', 'bbz', 'pga', 'he', 'iw', 'ps', 'pbt', 'pbu', 'pst', 'prp', 'prd', 'ug', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam', 'ckb'];
2071
2076
  const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
2077
+ if (lng.toLowerCase().indexOf('-latn') > 1) return 'ltr';
2072
2078
  return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
2073
2079
  }
2074
2080
  static createInstance(options = {}, callback) {