Skip to content

Commit 2881712

Browse files
authored
fix: yaml list format (#1644)
* fix: preserve list format in YAML files * chore: add changeset
1 parent 8a70413 commit 2881712

6 files changed

Lines changed: 98 additions & 38 deletions

File tree

.changeset/sixty-dryers-bake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
preserve list formatting in YAML files

packages/cli/demo/yaml-root-key/en/example.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,33 @@ en:
2323
F: :@f
2424
M: :@m
2525
N: :@n
26-
default: :m
26+
default: :m
27+
date:
28+
abbr_day_names:
29+
- "Mon"
30+
- "Tue"
31+
- "Wed"
32+
- "Thu"
33+
- "Fri"
34+
- "Sat"
35+
- "Sun"
36+
abbr_month_names:
37+
- null
38+
- "Jan"
39+
- "Feb"
40+
- "Mar"
41+
- "Apr"
42+
- "May"
43+
- "Jun"
44+
- "Jul"
45+
- "Aug"
46+
- "Sep"
47+
- "Oct"
48+
- "Nov"
49+
- "Dec"
50+
formats:
51+
default: "MM/dd/yyyy"
52+
long: "MMMM d, yyyy"
53+
short: "MM/dd/yy"
54+
time: "h:mm a"
55+
time_with_seconds: "h:mm:ss a"

packages/cli/demo/yaml-root-key/es/example.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,33 @@ es:
2323
F: :@f
2424
M: :@m
2525
N: :@n
26-
default: :m
26+
default: :m
27+
date:
28+
abbr_day_names:
29+
- "Lun"
30+
- "Mar"
31+
- "Mié"
32+
- "Jue"
33+
- "Vie"
34+
- "Sáb"
35+
- "Dom"
36+
abbr_month_names:
37+
- null
38+
- "Ene"
39+
- "Feb"
40+
- "Mar"
41+
- "Abr"
42+
- "May"
43+
- "Jun"
44+
- "Jul"
45+
- "Ago"
46+
- "Sep"
47+
- "Oct"
48+
- "Nov"
49+
- "Dic"
50+
formats:
51+
default: "dd/MM/yyyy"
52+
long: "d 'de' MMMM 'de' yyyy"
53+
short: "dd/MM/yy"
54+
time: "H:mm"
55+
time_with_seconds: "H:mm:ss"

packages/cli/demo/yaml/es/example.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ user_profile:
55
display_name: "John Doe"
66
bio: Desarrollador de software
77
navigation_items:
8-
- Inicio
9-
- Acerca de
10-
- Contacto
8+
- "Inicio"
9+
- "Acerca de"
10+
- "Contacto"
1111
product:
1212
name: "MyWidget"
1313
tagline: El mejor widget de todos
1414
features:
15-
- Fácil de usar
16-
- Rápido y confiable
15+
- "Fácil de usar"
16+
- "Rápido y confiable"
1717
settings:
1818
max_users: 100
1919
enabled: true

packages/cli/i18n.lock

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,30 @@ checksums:
631631
navigation/inflections/gender/M: 9ebdcb660f503bb2618ae7ae086617e2
632632
navigation/inflections/gender/N: 603743850a2510aaa6a5eb9dbfbe7416
633633
navigation/inflections/gender/default: 453a466f60641d9934bbee33dc4cd2b6
634+
date/abbr_day_names/0: b29e2b72f74643194654961775178fec
635+
date/abbr_day_names/1: b750502bab403473852a20cea73dcf2c
636+
date/abbr_day_names/2: 4786ce2a2427ad9183ef1a6f7385fb24
637+
date/abbr_day_names/3: ce25e3f9bfc6cfdc6017f791045da079
638+
date/abbr_day_names/4: 4029492def3bd66fa5a9d1c693743b62
639+
date/abbr_day_names/5: 0f0718f17b758ea9d5167c120c230be6
640+
date/abbr_day_names/6: 3b32ac0f13383ecdf580b4db09773fda
641+
date/abbr_month_names/1: 268e5f1e700c23c50b88e8c6aa754c88
642+
date/abbr_month_names/2: c111dae80531454da886782893e71541
643+
date/abbr_month_names/3: 3055ece906ba97d9b5050b4385d873a9
644+
date/abbr_month_names/4: 7a76ba706f71adc981bc050190ccc63f
645+
date/abbr_month_names/5: 320223c5afaaf28560a3a84d3527d51c
646+
date/abbr_month_names/6: 47f51f7cecc9bd30eef853748a40f2e7
647+
date/abbr_month_names/7: 5088467e6b771d6f02e1d4ea3550dd96
648+
date/abbr_month_names/8: 160006d60703204ab06369352f5f2520
649+
date/abbr_month_names/9: 91cac5f11e31c9907ea26a79fe5df889
650+
date/abbr_month_names/10: 384ae5bd38358c3f8db4560d59405c70
651+
date/abbr_month_names/11: a87c80252a5b03a82a0d16c510b5ed12
652+
date/abbr_month_names/12: 2a7ffd15bea3a6fdb664dff36b0e8043
653+
date/formats/default: df39f2ed8e14212ef5664e0603460e76
654+
date/formats/long: 60dc8afda933eee168c7eb73bda1a296
655+
date/formats/short: 05eb7bb8ee06c9de1435ba4cd1d81dcf
656+
date/formats/time: 1407af7bd151a6fa95e2d51497454cc2
657+
date/formats/time_with_seconds: f02992d40da922a1382859c45cb0231e
634658
1254631a73b754e11a1b9ca8f7362025:
635659
item_count/variations/plural: 2b2b1ff20c417ea68d07d66ba30a5c14
636660
notification_message/stringUnit: d14316154e233634917e317452c5f42c

packages/cli/src/cli/loaders/yaml.ts

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -236,44 +236,17 @@ function walkAndApply(
236236
}
237237
}
238238

239-
// Type guards
239+
// Type guards using YAML library's built-in functions
240240
function isScalar(node: any): boolean {
241-
if (node?.constructor?.name === "Scalar") {
242-
return true;
243-
}
244-
return (
245-
node &&
246-
typeof node === "object" &&
247-
"value" in node &&
248-
("type" in node || "format" in node)
249-
);
241+
return YAML.isScalar(node);
250242
}
251243

252244
function isYAMLMap(node: any): boolean {
253-
if (node?.constructor?.name === "YAMLMap") {
254-
return true;
255-
}
256-
return (
257-
node &&
258-
typeof node === "object" &&
259-
"items" in node &&
260-
Array.isArray(node.items) &&
261-
!("value" in node)
262-
);
245+
return YAML.isMap(node);
263246
}
264247

265248
function isYAMLSeq(node: any): boolean {
266-
if (node?.constructor?.name === "YAMLSeq") {
267-
return true;
268-
}
269-
return (
270-
node &&
271-
typeof node === "object" &&
272-
"items" in node &&
273-
Array.isArray(node.items) &&
274-
!("type" in node) &&
275-
!("value" in node)
276-
);
249+
return YAML.isSeq(node);
277250
}
278251

279252
function getKeyValue(key: any): string | number | null {

0 commit comments

Comments
 (0)