Skip to content

Commit 40dc1bb

Browse files
authored
chore: cldr loading (#1711)
* fix: cldr loading * chore: add changeset
1 parent ec231a8 commit 40dc1bb

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

.changeset/tall-owls-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@lingo.dev/_locales": patch
3+
---
4+
5+
Fix CLDR loading

packages/locales/src/names/loader.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
*/
55

66
// Base URL for CLDR data from GitHub
7-
const CLDR_BASE_URL =
8-
process.env.CLDR_BASE_URL ||
9-
"https://raw.githubusercontent.com/unicode-org/cldr-json/main/cldr-json/cldr-localenames-full/main";
7+
function getCLDRBaseUrl(): string {
8+
if (typeof process !== "undefined" && process.env?.CLDR_BASE_URL) {
9+
return process.env.CLDR_BASE_URL;
10+
}
11+
return "https://raw.githubusercontent.com/unicode-org/cldr-json/main/cldr-json/cldr-localenames-full/main";
12+
}
1013

1114
interface NameData {
1215
[key: string]: string;
@@ -30,7 +33,7 @@ export async function loadTerritoryNames(
3033
try {
3134
// Fetch from GitHub raw URL
3235
const response = await fetch(
33-
`${CLDR_BASE_URL}/${displayLanguage}/territories.json`,
36+
`${getCLDRBaseUrl()}/${displayLanguage}/territories.json`,
3437
);
3538

3639
if (!response.ok) {
@@ -71,7 +74,7 @@ export async function loadLanguageNames(
7174
try {
7275
// Fetch from GitHub raw URL
7376
const response = await fetch(
74-
`${CLDR_BASE_URL}/${displayLanguage}/languages.json`,
77+
`${getCLDRBaseUrl()}/${displayLanguage}/languages.json`,
7578
);
7679

7780
if (!response.ok) {
@@ -112,7 +115,7 @@ export async function loadScriptNames(
112115
try {
113116
// Fetch from GitHub raw URL
114117
const response = await fetch(
115-
`${CLDR_BASE_URL}/${displayLanguage}/scripts.json`,
118+
`${getCLDRBaseUrl()}/${displayLanguage}/scripts.json`,
116119
);
117120

118121
if (!response.ok) {

0 commit comments

Comments
 (0)