Skip to content

Commit

Permalink
Merge pull request #18 from sillsdev/langtagProcessing_script_fix
Browse files Browse the repository at this point in the history
fix: langtagProcessing.ts script (#18)
  • Loading branch information
andrew-polk authored Oct 11, 2024
2 parents 1603085 + c42c460 commit 575b3b9
Show file tree
Hide file tree
Showing 6 changed files with 1,871 additions and 3,854 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { iso15924 } from "iso-15924";
import langTagsJson from "./language-data/langtags.json" assert { type: "json" };
import * as fs from "fs";
import fs from "fs";
import { ILanguage, IScript } from "./findLanguageInterfaces";
// import iso3166 from "iso-3166-1";

Expand All @@ -9,7 +9,7 @@ const COMMA_SEPARATOR = ", ";
const scriptNames = iso15924.reduce(
(acc, entry) => ({ ...acc, [entry.code]: entry.name }),
{}
);
) as any;

// const regionNames = iso3166
// .all()
Expand Down Expand Up @@ -80,15 +80,15 @@ function getAllPossibleNames(entry: any) {
]);
}

function autonymOrFallback(entry: any, fallback: string) {
function autonymOrFallback(entry: any, fallback: string | undefined) {
// We are currently ignoring the "localname" field because it appears to be more specific than what we want,
// e.g. the "es-Latn-ES" entry of langtags.json has "localname": "español de España" and "localnames": [ "castellano", "español" ]
return entry.localnames ? entry.localnames[0] : undefined ?? fallback;
}

// We want to have one entry for every ISO 639-3 code, whereas langtags.json sometimes has multiple entries per code
// Combine entry into the entry with matching ISO 630-3 code in langs if there is one, otherwise create a new entry
function addOrCombineLangtagsEntry(entry, langs) {
function addOrCombineLangtagsEntry(entry: any, langs: any) {
if (!entry.iso639_3) {
// langTags.json has metadata items in the same list mixed in with the data entries
return;
Expand Down Expand Up @@ -166,7 +166,7 @@ function parseLangtagsJson() {

// Tweak some of the data into the format we want
const reformattedLangs = Object.values(consolidatedLangTags).map(
(langData: ILanguageInternal) => {
(langData: any) => {
// Don't repeat the autonym and exonym in the names list
langData.names.delete(langData.autonym);
langData.names.delete(langData.exonym);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"devDependencies": {
"@nx/vite": "^19.1.2",
"@types/node": "^20.14.11",
"@types/node": "^20.16.11",
"ts-node": "^10.9.2",
"typescript": "^5.2.2"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"types": ["vite/client"]

},
"ts-node": {
"moduleTypes": {
"*": "esm"
}
},
"files": [],
"include": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"**/*.spec.jsx",
"**/*.test.jsx"
],
"include": ["./**/*.js", "./**/*.jsx", "./**/*.ts", "./**/*.tsx", "langtagProcessing.ts"]
"include": ["./**/*.js", "./**/*.jsx", "./**/*.ts", "./**/*.tsx"]
}
Loading

0 comments on commit 575b3b9

Please sign in to comment.