-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve handling of language codes, clean up code
- Loading branch information
Showing
6 changed files
with
62 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export function englishNameFromCode(code: string): string { | ||
const locale = new Intl.Locale(code); | ||
return new Intl.DisplayNames(['en'], { type: 'language' }).of(locale.language) ?? ''; | ||
} | ||
|
||
export function areLanguageCodesEquivalent(code1: string, code2: string): boolean { | ||
return code1 === code2 || englishNameFromCode(code1) === englishNameFromCode(code2); | ||
} | ||
|
||
/** | ||
* Given a list of language codes, counts the number of codes that are "unique" in the sense that they have different | ||
* English names. | ||
* | ||
* This is a *very rough* way of determining whether languages are "equivalent" for the purposes of training a model. | ||
* | ||
* As an example, zh and cmn both map to "Chinese" in English, so they would be considered equivalent. | ||
* | ||
* TODO Create a more robust way of determining whether languages are equivalent, that isn't browser-dependent. | ||
*/ | ||
export function countNonEquivalentLanguageCodes(languageCodes: string[]): number { | ||
const uniqueTags = new Set(languageCodes); | ||
return new Set(Array.from(uniqueTags).map(englishNameFromCode)).size; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters