lingo.dev 0.116.3 → 0.116.4

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/build/cli.cjs CHANGED
@@ -1619,8 +1619,8 @@ function createLoader(lDefinition) {
1619
1619
  state.defaultLocale = locale;
1620
1620
  return this;
1621
1621
  },
1622
- async pullHints() {
1623
- return _optionalChain([lDefinition, 'access', _101 => _101.pullHints, 'optionalCall', _102 => _102(state.originalInput)]);
1622
+ async pullHints(originalInput) {
1623
+ return _optionalChain([lDefinition, 'access', _101 => _101.pullHints, 'optionalCall', _102 => _102(originalInput || state.originalInput)]);
1624
1624
  },
1625
1625
  async pull(locale, input2) {
1626
1626
  if (!state.defaultLocale) {
@@ -4192,19 +4192,44 @@ function _removeLocale(input2, locale) {
4192
4192
 
4193
4193
  // src/cli/loaders/xcode-xcstrings-v2.ts
4194
4194
 
4195
- function buildIcuPluralString(forms) {
4196
- const parts = Object.entries(forms).map(
4197
- ([form, text]) => `${form} {${text}}`
4198
- );
4195
+ function getRequiredPluralCategories(locale) {
4196
+ try {
4197
+ const pluralRules = new Intl.PluralRules(locale);
4198
+ const categories = pluralRules.resolvedOptions().pluralCategories;
4199
+ if (!categories || categories.length === 0) {
4200
+ return ["other"];
4201
+ }
4202
+ return categories;
4203
+ } catch (error) {
4204
+ return ["other"];
4205
+ }
4206
+ }
4207
+ function isValidPluralForm(form, locale) {
4208
+ if (form.startsWith("=")) return true;
4209
+ const requiredCategories = getRequiredPluralCategories(locale);
4210
+ return requiredCategories.includes(form);
4211
+ }
4212
+ function buildIcuPluralString(forms, sourceLocale) {
4213
+ const requiredCategories = new Set(getRequiredPluralCategories(sourceLocale));
4214
+ const parts = Object.entries(forms).map(([form, text]) => {
4215
+ let normalizedForm = form;
4216
+ if (!requiredCategories.has(form)) {
4217
+ if (form === "zero") normalizedForm = "=0";
4218
+ else if (form === "one") normalizedForm = "=1";
4219
+ else if (form === "two") normalizedForm = "=2";
4220
+ }
4221
+ return `${normalizedForm} {${text}}`;
4222
+ });
4199
4223
  return `{count, plural, ${parts.join(" ")}}`;
4200
4224
  }
4201
- function parseIcuPluralString(icuString) {
4225
+ function parseIcuPluralString(icuString, locale) {
4202
4226
  const pluralMatch = icuString.match(/\{[\w]+,\s*plural,\s*(.+)\}$/);
4203
4227
  if (!pluralMatch) {
4204
4228
  throw new Error(`Invalid ICU plural format: ${icuString}`);
4205
4229
  }
4206
4230
  const formsText = pluralMatch[1];
4207
4231
  const forms = {};
4232
+ const exactMatches = /* @__PURE__ */ new Set();
4208
4233
  let i = 0;
4209
4234
  while (i < formsText.length) {
4210
4235
  while (i < formsText.length && /\s/.test(formsText[i])) {
@@ -4226,6 +4251,16 @@ function parseIcuPluralString(icuString) {
4226
4251
  }
4227
4252
  }
4228
4253
  if (!formName) break;
4254
+ if (formName === "=0") {
4255
+ formName = "zero";
4256
+ exactMatches.add("zero");
4257
+ } else if (formName === "=1") {
4258
+ formName = "one";
4259
+ exactMatches.add("one");
4260
+ } else if (formName === "=2") {
4261
+ formName = "two";
4262
+ exactMatches.add("two");
4263
+ }
4229
4264
  while (i < formsText.length && /\s/.test(formsText[i])) {
4230
4265
  i++;
4231
4266
  }
@@ -4256,7 +4291,13 @@ function parseIcuPluralString(icuString) {
4256
4291
  }
4257
4292
  forms[formName] = formText;
4258
4293
  }
4259
- return forms;
4294
+ const filteredForms = {};
4295
+ for (const [form, text] of Object.entries(forms)) {
4296
+ if (exactMatches.has(form) || isValidPluralForm(form, locale)) {
4297
+ filteredForms[form] = text;
4298
+ }
4299
+ }
4300
+ return filteredForms;
4260
4301
  }
4261
4302
  function isIcuPluralString(value) {
4262
4303
  return typeof value === "string" && /^\{[\w]+,\s*plural,\s*.+\}$/.test(value);
@@ -4291,7 +4332,7 @@ function createXcodeXcstringsV2Loader(defaultLocale) {
4291
4332
  for (const [form, formData] of Object.entries(pluralForms)) {
4292
4333
  forms[form] = formData.stringUnit.value;
4293
4334
  }
4294
- const icuString = buildIcuPluralString(forms);
4335
+ const icuString = buildIcuPluralString(forms, locale);
4295
4336
  resultData[translationKey].substitutions[subName] = {
4296
4337
  variations: {
4297
4338
  plural: icuString
@@ -4314,7 +4355,7 @@ function createXcodeXcstringsV2Loader(defaultLocale) {
4314
4355
  forms[form] = formData.stringUnit.value;
4315
4356
  }
4316
4357
  }
4317
- const icuString = buildIcuPluralString(forms);
4358
+ const icuString = buildIcuPluralString(forms, locale);
4318
4359
  resultData[translationKey].variations = {
4319
4360
  plural: icuString
4320
4361
  };
@@ -4356,7 +4397,7 @@ function createXcodeXcstringsV2Loader(defaultLocale) {
4356
4397
  const pluralValue = _optionalChain([subData, 'optionalAccess', _196 => _196.variations, 'optionalAccess', _197 => _197.plural]);
4357
4398
  if (pluralValue && isIcuPluralString(pluralValue)) {
4358
4399
  try {
4359
- const pluralForms = parseIcuPluralString(pluralValue);
4400
+ const pluralForms = parseIcuPluralString(pluralValue, locale);
4360
4401
  const pluralOut = {};
4361
4402
  for (const [form, text] of Object.entries(pluralForms)) {
4362
4403
  pluralOut[form] = {
@@ -4396,7 +4437,7 @@ ${error instanceof Error ? error.message : String(error)}`
4396
4437
  const pluralValue = keyData.variations.plural;
4397
4438
  if (isIcuPluralString(pluralValue)) {
4398
4439
  try {
4399
- const pluralForms = parseIcuPluralString(pluralValue);
4440
+ const pluralForms = parseIcuPluralString(pluralValue, locale);
4400
4441
  const pluralOut = {};
4401
4442
  for (const [form, text] of Object.entries(pluralForms)) {
4402
4443
  pluralOut[form] = {
@@ -9801,35 +9842,6 @@ function createDeltaProcessor(fileKey) {
9801
9842
  };
9802
9843
  }
9803
9844
 
9804
- // src/cli/loaders/xcode-xcstrings-icu.ts
9805
- var ICU_TYPE_MARKER = Symbol.for("@lingo.dev/icu-plural-object");
9806
- function isICUPluralObject(value) {
9807
- if (!value || typeof value !== "object" || Array.isArray(value)) {
9808
- return false;
9809
- }
9810
- if (ICU_TYPE_MARKER in value) {
9811
- return true;
9812
- }
9813
- if (!("icu" in value) || typeof value.icu !== "string") {
9814
- return false;
9815
- }
9816
- const icuPluralPattern = /^\{[\w]+,\s*plural,\s*.+\}$/;
9817
- if (!icuPluralPattern.test(value.icu)) {
9818
- return false;
9819
- }
9820
- if (value._meta !== void 0) {
9821
- if (typeof value._meta !== "object" || !value._meta.variables || typeof value._meta.variables !== "object") {
9822
- return false;
9823
- }
9824
- for (const [varName, varMeta] of Object.entries(value._meta.variables)) {
9825
- if (!varMeta || typeof varMeta !== "object" || typeof varMeta.format !== "string" || varMeta.role !== "plural" && varMeta.role !== "other") {
9826
- return false;
9827
- }
9828
- }
9829
- }
9830
- return true;
9831
- }
9832
-
9833
9845
  // src/cli/cmd/i18n.ts
9834
9846
  var i18n_default = new (0, _interactivecommander.Command)().command("i18n").description(
9835
9847
  "DEPRECATED: Run localization pipeline (prefer `run` command instead)"
@@ -10194,11 +10206,8 @@ var i18n_default = new (0, _interactivecommander.Command)().command("i18n").desc
10194
10206
  }
10195
10207
  const finalDiffSize = _lodash2.default.chain(finalTargetData).omitBy((value, key) => {
10196
10208
  const targetValue = targetData[key];
10197
- if (isICUPluralObject(value) && isICUPluralObject(targetValue)) {
10198
- return _lodash2.default.isEqual(
10199
- { icu: value.icu, _meta: value._meta },
10200
- { icu: targetValue.icu, _meta: targetValue._meta }
10201
- );
10209
+ if (typeof value === "object" && value !== null) {
10210
+ return _lodash2.default.isEqual(value, targetValue);
10202
10211
  }
10203
10212
  return value === targetValue;
10204
10213
  }).size().value();
@@ -13456,7 +13465,7 @@ async function renderHero2() {
13456
13465
  // package.json
13457
13466
  var package_default = {
13458
13467
  name: "lingo.dev",
13459
- version: "0.116.3",
13468
+ version: "0.116.4",
13460
13469
  description: "Lingo.dev CLI",
13461
13470
  private: false,
13462
13471
  publishConfig: {