lingo.dev 0.116.3 → 0.116.5

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.mjs CHANGED
@@ -1615,8 +1615,8 @@ function createLoader(lDefinition) {
1615
1615
  state.defaultLocale = locale;
1616
1616
  return this;
1617
1617
  },
1618
- async pullHints() {
1619
- return lDefinition.pullHints?.(state.originalInput);
1618
+ async pullHints(originalInput) {
1619
+ return lDefinition.pullHints?.(originalInput || state.originalInput);
1620
1620
  },
1621
1621
  async pull(locale, input2) {
1622
1622
  if (!state.defaultLocale) {
@@ -2107,6 +2107,13 @@ function getKeyType(yamlString) {
2107
2107
  function getStringType(yamlString) {
2108
2108
  if (yamlString) {
2109
2109
  const lines = yamlString.split("\n");
2110
+ const hasLiteralBlockScalar = lines.find((line) => {
2111
+ const trimmedLine = line.trim();
2112
+ return trimmedLine.match(/:\s*\|[-+]?\s*$/);
2113
+ });
2114
+ if (hasLiteralBlockScalar) {
2115
+ return "PLAIN";
2116
+ }
2110
2117
  const hasDoubleQuotes = lines.find((line) => {
2111
2118
  const trimmedLine = line.trim();
2112
2119
  return (trimmedLine.startsWith('"') || trimmedLine.match(/:\s*"/)) && (trimmedLine.endsWith('"') || trimmedLine.endsWith('",'));
@@ -4188,19 +4195,44 @@ function _removeLocale(input2, locale) {
4188
4195
 
4189
4196
  // src/cli/loaders/xcode-xcstrings-v2.ts
4190
4197
  import _10 from "lodash";
4191
- function buildIcuPluralString(forms) {
4192
- const parts = Object.entries(forms).map(
4193
- ([form, text]) => `${form} {${text}}`
4194
- );
4198
+ function getRequiredPluralCategories(locale) {
4199
+ try {
4200
+ const pluralRules = new Intl.PluralRules(locale);
4201
+ const categories = pluralRules.resolvedOptions().pluralCategories;
4202
+ if (!categories || categories.length === 0) {
4203
+ return ["other"];
4204
+ }
4205
+ return categories;
4206
+ } catch (error) {
4207
+ return ["other"];
4208
+ }
4209
+ }
4210
+ function isValidPluralForm(form, locale) {
4211
+ if (form.startsWith("=")) return true;
4212
+ const requiredCategories = getRequiredPluralCategories(locale);
4213
+ return requiredCategories.includes(form);
4214
+ }
4215
+ function buildIcuPluralString(forms, sourceLocale) {
4216
+ const requiredCategories = new Set(getRequiredPluralCategories(sourceLocale));
4217
+ const parts = Object.entries(forms).map(([form, text]) => {
4218
+ let normalizedForm = form;
4219
+ if (!requiredCategories.has(form)) {
4220
+ if (form === "zero") normalizedForm = "=0";
4221
+ else if (form === "one") normalizedForm = "=1";
4222
+ else if (form === "two") normalizedForm = "=2";
4223
+ }
4224
+ return `${normalizedForm} {${text}}`;
4225
+ });
4195
4226
  return `{count, plural, ${parts.join(" ")}}`;
4196
4227
  }
4197
- function parseIcuPluralString(icuString) {
4228
+ function parseIcuPluralString(icuString, locale) {
4198
4229
  const pluralMatch = icuString.match(/\{[\w]+,\s*plural,\s*(.+)\}$/);
4199
4230
  if (!pluralMatch) {
4200
4231
  throw new Error(`Invalid ICU plural format: ${icuString}`);
4201
4232
  }
4202
4233
  const formsText = pluralMatch[1];
4203
4234
  const forms = {};
4235
+ const exactMatches = /* @__PURE__ */ new Set();
4204
4236
  let i = 0;
4205
4237
  while (i < formsText.length) {
4206
4238
  while (i < formsText.length && /\s/.test(formsText[i])) {
@@ -4222,6 +4254,16 @@ function parseIcuPluralString(icuString) {
4222
4254
  }
4223
4255
  }
4224
4256
  if (!formName) break;
4257
+ if (formName === "=0") {
4258
+ formName = "zero";
4259
+ exactMatches.add("zero");
4260
+ } else if (formName === "=1") {
4261
+ formName = "one";
4262
+ exactMatches.add("one");
4263
+ } else if (formName === "=2") {
4264
+ formName = "two";
4265
+ exactMatches.add("two");
4266
+ }
4225
4267
  while (i < formsText.length && /\s/.test(formsText[i])) {
4226
4268
  i++;
4227
4269
  }
@@ -4252,7 +4294,13 @@ function parseIcuPluralString(icuString) {
4252
4294
  }
4253
4295
  forms[formName] = formText;
4254
4296
  }
4255
- return forms;
4297
+ const filteredForms = {};
4298
+ for (const [form, text] of Object.entries(forms)) {
4299
+ if (exactMatches.has(form) || isValidPluralForm(form, locale)) {
4300
+ filteredForms[form] = text;
4301
+ }
4302
+ }
4303
+ return filteredForms;
4256
4304
  }
4257
4305
  function isIcuPluralString(value) {
4258
4306
  return typeof value === "string" && /^\{[\w]+,\s*plural,\s*.+\}$/.test(value);
@@ -4287,7 +4335,7 @@ function createXcodeXcstringsV2Loader(defaultLocale) {
4287
4335
  for (const [form, formData] of Object.entries(pluralForms)) {
4288
4336
  forms[form] = formData.stringUnit.value;
4289
4337
  }
4290
- const icuString = buildIcuPluralString(forms);
4338
+ const icuString = buildIcuPluralString(forms, locale);
4291
4339
  resultData[translationKey].substitutions[subName] = {
4292
4340
  variations: {
4293
4341
  plural: icuString
@@ -4310,7 +4358,7 @@ function createXcodeXcstringsV2Loader(defaultLocale) {
4310
4358
  forms[form] = formData.stringUnit.value;
4311
4359
  }
4312
4360
  }
4313
- const icuString = buildIcuPluralString(forms);
4361
+ const icuString = buildIcuPluralString(forms, locale);
4314
4362
  resultData[translationKey].variations = {
4315
4363
  plural: icuString
4316
4364
  };
@@ -4352,7 +4400,7 @@ function createXcodeXcstringsV2Loader(defaultLocale) {
4352
4400
  const pluralValue = subData?.variations?.plural;
4353
4401
  if (pluralValue && isIcuPluralString(pluralValue)) {
4354
4402
  try {
4355
- const pluralForms = parseIcuPluralString(pluralValue);
4403
+ const pluralForms = parseIcuPluralString(pluralValue, locale);
4356
4404
  const pluralOut = {};
4357
4405
  for (const [form, text] of Object.entries(pluralForms)) {
4358
4406
  pluralOut[form] = {
@@ -4392,7 +4440,7 @@ ${error instanceof Error ? error.message : String(error)}`
4392
4440
  const pluralValue = keyData.variations.plural;
4393
4441
  if (isIcuPluralString(pluralValue)) {
4394
4442
  try {
4395
- const pluralForms = parseIcuPluralString(pluralValue);
4443
+ const pluralForms = parseIcuPluralString(pluralValue, locale);
4396
4444
  const pluralOut = {};
4397
4445
  for (const [form, text] of Object.entries(pluralForms)) {
4398
4446
  pluralOut[form] = {
@@ -9797,35 +9845,6 @@ function createDeltaProcessor(fileKey) {
9797
9845
  };
9798
9846
  }
9799
9847
 
9800
- // src/cli/loaders/xcode-xcstrings-icu.ts
9801
- var ICU_TYPE_MARKER = Symbol.for("@lingo.dev/icu-plural-object");
9802
- function isICUPluralObject(value) {
9803
- if (!value || typeof value !== "object" || Array.isArray(value)) {
9804
- return false;
9805
- }
9806
- if (ICU_TYPE_MARKER in value) {
9807
- return true;
9808
- }
9809
- if (!("icu" in value) || typeof value.icu !== "string") {
9810
- return false;
9811
- }
9812
- const icuPluralPattern = /^\{[\w]+,\s*plural,\s*.+\}$/;
9813
- if (!icuPluralPattern.test(value.icu)) {
9814
- return false;
9815
- }
9816
- if (value._meta !== void 0) {
9817
- if (typeof value._meta !== "object" || !value._meta.variables || typeof value._meta.variables !== "object") {
9818
- return false;
9819
- }
9820
- for (const [varName, varMeta] of Object.entries(value._meta.variables)) {
9821
- if (!varMeta || typeof varMeta !== "object" || typeof varMeta.format !== "string" || varMeta.role !== "plural" && varMeta.role !== "other") {
9822
- return false;
9823
- }
9824
- }
9825
- }
9826
- return true;
9827
- }
9828
-
9829
9848
  // src/cli/cmd/i18n.ts
9830
9849
  var i18n_default = new Command14().command("i18n").description(
9831
9850
  "DEPRECATED: Run localization pipeline (prefer `run` command instead)"
@@ -10190,11 +10209,8 @@ var i18n_default = new Command14().command("i18n").description(
10190
10209
  }
10191
10210
  const finalDiffSize = _32.chain(finalTargetData).omitBy((value, key) => {
10192
10211
  const targetValue = targetData[key];
10193
- if (isICUPluralObject(value) && isICUPluralObject(targetValue)) {
10194
- return _32.isEqual(
10195
- { icu: value.icu, _meta: value._meta },
10196
- { icu: targetValue.icu, _meta: targetValue._meta }
10197
- );
10212
+ if (typeof value === "object" && value !== null) {
10213
+ return _32.isEqual(value, targetValue);
10198
10214
  }
10199
10215
  return value === targetValue;
10200
10216
  }).size().value();
@@ -13452,7 +13468,7 @@ async function renderHero2() {
13452
13468
  // package.json
13453
13469
  var package_default = {
13454
13470
  name: "lingo.dev",
13455
- version: "0.116.3",
13471
+ version: "0.116.5",
13456
13472
  description: "Lingo.dev CLI",
13457
13473
  private: false,
13458
13474
  publishConfig: {