lingo.dev 0.117.8 → 0.117.9

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
@@ -2321,9 +2321,119 @@ function _isMetadataKey(key) {
2321
2321
  return key.startsWith("@");
2322
2322
  }
2323
2323
 
2324
+ // src/cli/loaders/ail.ts
2325
+ import { parseStringPromise, Builder } from "xml2js";
2326
+ function createAilLoader() {
2327
+ return createLoader({
2328
+ async pull(locale, input2) {
2329
+ const result = {};
2330
+ if (!input2 || !input2.trim()) {
2331
+ return result;
2332
+ }
2333
+ try {
2334
+ const parsed = await parseStringPromise(input2, {
2335
+ explicitArray: true,
2336
+ // Always use arrays for consistency
2337
+ mergeAttrs: false,
2338
+ // Keep attributes separate in $
2339
+ trim: true,
2340
+ explicitRoot: true
2341
+ });
2342
+ const dictionary = parsed.DICTIONARY;
2343
+ if (!dictionary) {
2344
+ return result;
2345
+ }
2346
+ const entries = dictionary.ENTRY || [];
2347
+ for (const entry of entries) {
2348
+ const id = entry.$?.id;
2349
+ if (!id) {
2350
+ continue;
2351
+ }
2352
+ const strings = entry.STRING || [];
2353
+ const sourceString = strings.find(
2354
+ (s) => s.$?.lang === locale
2355
+ );
2356
+ if (sourceString?.$.value) {
2357
+ result[id] = sourceString.$.value;
2358
+ }
2359
+ }
2360
+ return result;
2361
+ } catch (error) {
2362
+ console.error("Failed to parse AIL file:", error);
2363
+ return result;
2364
+ }
2365
+ },
2366
+ async push(locale, data, originalInput) {
2367
+ if (!originalInput || !originalInput.trim()) {
2368
+ const dictionary = {
2369
+ $: { type: "multilanguage" },
2370
+ ENTRY: Object.entries(data).map(([id, value]) => ({
2371
+ $: { id },
2372
+ STRING: [
2373
+ {
2374
+ $: { lang: locale, value }
2375
+ }
2376
+ ]
2377
+ }))
2378
+ };
2379
+ const builder = new Builder({
2380
+ xmldec: { version: "1.0", encoding: "UTF-8" },
2381
+ headless: false
2382
+ });
2383
+ return builder.buildObject({ DICTIONARY: dictionary });
2384
+ }
2385
+ try {
2386
+ const parsed = await parseStringPromise(originalInput, {
2387
+ explicitArray: true,
2388
+ mergeAttrs: false,
2389
+ trim: true,
2390
+ explicitRoot: true
2391
+ });
2392
+ const dictionary = parsed.DICTIONARY;
2393
+ if (!dictionary) {
2394
+ throw new Error("No DICTIONARY root element found");
2395
+ }
2396
+ const entries = dictionary.ENTRY || [];
2397
+ for (const [id, value] of Object.entries(data)) {
2398
+ let entry = entries.find((e) => e.$?.id === id);
2399
+ if (!entry) {
2400
+ entry = {
2401
+ $: { id },
2402
+ STRING: []
2403
+ };
2404
+ entries.push(entry);
2405
+ }
2406
+ if (!entry.STRING) {
2407
+ entry.STRING = [];
2408
+ }
2409
+ let targetString = entry.STRING.find(
2410
+ (s) => s.$?.lang === locale
2411
+ );
2412
+ if (targetString) {
2413
+ targetString.$.value = value;
2414
+ } else {
2415
+ entry.STRING.push({
2416
+ $: { lang: locale, value }
2417
+ });
2418
+ }
2419
+ }
2420
+ dictionary.ENTRY = entries;
2421
+ const builder = new Builder({
2422
+ xmldec: { version: "1.0", encoding: "UTF-8" },
2423
+ headless: false
2424
+ });
2425
+ return builder.buildObject({ DICTIONARY: dictionary });
2426
+ } catch (error) {
2427
+ console.error("Failed to build AIL file:", error);
2428
+ throw error;
2429
+ }
2430
+ }
2431
+ });
2432
+ }
2433
+
2324
2434
  // src/cli/loaders/android.ts
2325
2435
  import { createRequire } from "module";
2326
- import { parseStringPromise } from "xml2js";
2436
+ import { parseStringPromise as parseStringPromise2 } from "xml2js";
2327
2437
  var require2 = createRequire(import.meta.url);
2328
2438
  var sax = require2("sax");
2329
2439
  var defaultAndroidResourcesXml = `<?xml version="1.0" encoding="utf-8"?>
@@ -2401,7 +2511,7 @@ function resolveXmlDeclaration(xml) {
2401
2511
  }
2402
2512
  async function parseAndroidDocument(input2) {
2403
2513
  const xmlToParse = input2 && input2.trim().length > 0 ? input2 : defaultAndroidResourcesXml;
2404
- const parsed = await parseStringPromise(xmlToParse, {
2514
+ const parsed = await parseStringPromise2(xmlToParse, {
2405
2515
  explicitArray: true,
2406
2516
  explicitChildren: true,
2407
2517
  preserveChildrenOrder: true,
@@ -4005,7 +4115,7 @@ function applyTranslations(node, path19, data, pathMap) {
4005
4115
  }
4006
4116
 
4007
4117
  // src/cli/loaders/mjml.ts
4008
- import { parseStringPromise as parseStringPromise2 } from "xml2js";
4118
+ import { parseStringPromise as parseStringPromise3 } from "xml2js";
4009
4119
  import * as htmlparser22 from "htmlparser2";
4010
4120
  import { DomHandler as DomHandler2 } from "domhandler";
4011
4121
  var LOCALIZABLE_COMPONENTS = [
@@ -4037,7 +4147,7 @@ function createMjmlLoader() {
4037
4147
  async pull(locale, input2) {
4038
4148
  const result = {};
4039
4149
  try {
4040
- const parsed = await parseStringPromise2(input2, {
4150
+ const parsed = await parseStringPromise3(input2, {
4041
4151
  explicitArray: true,
4042
4152
  explicitChildren: true,
4043
4153
  preserveChildrenOrder: true,
@@ -4083,7 +4193,7 @@ function createMjmlLoader() {
4083
4193
  },
4084
4194
  async push(locale, data, originalInput) {
4085
4195
  try {
4086
- const parsed = await parseStringPromise2(originalInput || "", {
4196
+ const parsed = await parseStringPromise3(originalInput || "", {
4087
4197
  explicitArray: true,
4088
4198
  explicitChildren: true,
4089
4199
  preserveChildrenOrder: true,
@@ -5865,7 +5975,7 @@ function pushNewFile(locale, translations, originalLocale) {
5865
5975
  }
5866
5976
 
5867
5977
  // src/cli/loaders/xml.ts
5868
- import { parseStringPromise as parseStringPromise3, Builder as Builder2 } from "xml2js";
5978
+ import { parseStringPromise as parseStringPromise4, Builder as Builder3 } from "xml2js";
5869
5979
  function normalizeXMLString(xmlString) {
5870
5980
  return xmlString.replace(/\s+/g, " ").replace(/>\s+</g, "><").replace("\n", "").trim();
5871
5981
  }
@@ -5874,7 +5984,7 @@ function createXmlLoader() {
5874
5984
  async pull(locale, input2) {
5875
5985
  let result = {};
5876
5986
  try {
5877
- const parsed = await parseStringPromise3(input2, {
5987
+ const parsed = await parseStringPromise4(input2, {
5878
5988
  explicitArray: false,
5879
5989
  mergeAttrs: false,
5880
5990
  normalize: true,
@@ -5892,7 +6002,7 @@ function createXmlLoader() {
5892
6002
  },
5893
6003
  async push(locale, data) {
5894
6004
  try {
5895
- const builder = new Builder2({ headless: true });
6005
+ const builder = new Builder3({ headless: true });
5896
6006
  const xmlOutput = builder.buildObject(data);
5897
6007
  const expectedOutput = normalizeXMLString(xmlOutput);
5898
6008
  return expectedOutput;
@@ -9746,6 +9856,18 @@ function createBucketLoader(bucketType, bucketPathPattern, options, lockedKeys,
9746
9856
  switch (bucketType) {
9747
9857
  default:
9748
9858
  throw new Error(`Unsupported bucket type: ${bucketType}`);
9859
+ case "ail":
9860
+ return composeLoaders(
9861
+ createTextFileLoader(bucketPathPattern),
9862
+ createLockedPatternsLoader(lockedPatterns),
9863
+ createAilLoader(),
9864
+ createEnsureKeyOrderLoader(),
9865
+ createFlatLoader(),
9866
+ createLockedKeysLoader(lockedKeys || []),
9867
+ createIgnoredKeysLoader(ignoredKeys || []),
9868
+ createSyncLoader(),
9869
+ createUnlocalizableLoader(options.returnUnlocalizedKeys)
9870
+ );
9749
9871
  case "android":
9750
9872
  return composeLoaders(
9751
9873
  createTextFileLoader(bucketPathPattern),
@@ -14473,7 +14595,7 @@ async function renderHero2() {
14473
14595
  // package.json
14474
14596
  var package_default = {
14475
14597
  name: "lingo.dev",
14476
- version: "0.117.8",
14598
+ version: "0.117.9",
14477
14599
  description: "Lingo.dev CLI",
14478
14600
  private: false,
14479
14601
  publishConfig: {