|
1 | 1 | import Ajv from 'ajv/dist/jtd.js' |
2 | | -import translations from '../../lib/language_specific_translation/translations.js' |
3 | | -import bcp47 from 'bcp47' |
| 2 | +import { |
| 3 | + containsOneNoteWithTitleAndCategory, |
| 4 | + getTranslationInDocumentLang, |
| 5 | + isLangSpecifiedAndNotEnglish, |
| 6 | +} from '../../lib/shared/languageSpecificTranslation.js' |
4 | 7 |
|
5 | 8 | const ajv = new Ajv() |
6 | 9 |
|
@@ -42,55 +45,6 @@ const inputSchema = /** @type {const} */ ({ |
42 | 45 |
|
43 | 46 | const validateSchema = ajv.compile(inputSchema) |
44 | 47 |
|
45 | | -/** |
46 | | - * Checks if the document language is specified and not English |
47 | | - * |
48 | | - * @param {string | undefined} language - The language expression to check |
49 | | - * @returns {boolean} True if the language is valid, false otherwise |
50 | | - */ |
51 | | -export function isLangSpecifiedAndNotEnglish(language) { |
52 | | - return ( |
53 | | - !!language && !(bcp47.parse(language)?.langtag.language.language === 'en') |
54 | | - ) |
55 | | -} |
56 | | - |
57 | | -/** |
58 | | - * test whether exactly one item in document notes exists that has the given title. |
59 | | - * and the given category. |
60 | | - * @param {({} & { category?: string | undefined; title?: string | undefined; } & Record<string, unknown>)[]} notes |
61 | | - * @param {string} titleToFind |
62 | | - * @param {string} category |
63 | | - * @returns {boolean} True if the language is valid, false otherwise |
64 | | - */ |
65 | | -function containsOneNoteWithTitleAndCategory(notes, titleToFind, category) { |
66 | | - return ( |
67 | | - notes.filter( |
68 | | - (note) => note.category === category && note.title === titleToFind |
69 | | - ).length === 1 |
70 | | - ) |
71 | | -} |
72 | | - |
73 | | -/** |
74 | | - * Get the language specific translation of the given i18nKey |
75 | | - * @param {{ document: { lang?: string; }; }} doc |
76 | | - * @param {string} i18nKey |
77 | | - * @return {string | undefined} |
78 | | - */ |
79 | | -export function getTranslationInDocumentLang(doc, i18nKey) { |
80 | | - if (!doc.document.lang) { |
81 | | - return undefined |
82 | | - } |
83 | | - const language = bcp47.parse(doc.document.lang)?.langtag.language.language |
84 | | - |
85 | | - /** @type {Record<string, Record <string,string>>}*/ |
86 | | - const translationByLang = translations.translation |
87 | | - if (!language || !translationByLang[language]) { |
88 | | - return undefined |
89 | | - } else { |
90 | | - return translationByLang[language][i18nKey] |
91 | | - } |
92 | | -} |
93 | | - |
94 | 48 | /** |
95 | 49 | * If the document language is specified but not English, and the license_expression contains license |
96 | 50 | * identifiers or exceptions that are not listed in the SPDX license list or Aboutcode's "ScanCode LicenseDB", |
|
0 commit comments