-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95939a4
commit 0a42ad0
Showing
7 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,25 @@ | ||
import { readFileSync } from 'node:fs'; | ||
import { join } from 'node:path'; | ||
|
||
const registry = new Map<string, unknown>(); | ||
|
||
export default function getJsonData(name: string) { | ||
if (registry.has(name)) { | ||
return registry.get(name); | ||
} | ||
const PATH_TO_LOCALIZED_CONTENT = process.env.PATH_TO_LOCALIZED_CONTENT; | ||
if (!PATH_TO_LOCALIZED_CONTENT) { | ||
throw new Error('PATH_TO_LOCALIZED_CONTENT is not defined'); | ||
} | ||
const targetLocale = process.env.TARGET_LOCALE; | ||
if (!targetLocale) { | ||
throw new Error('TARGET_LOCALE is not defined'); | ||
} | ||
const json = readFileSync( | ||
join(PATH_TO_LOCALIZED_CONTENT, 'files', 'jsondata', `${name}.json`), | ||
'utf8', | ||
); | ||
const data = JSON.parse(json); | ||
registry.set(name, data); | ||
return data; | ||
} |
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,13 @@ | ||
import { z } from 'zod'; | ||
|
||
import getJsonData from './get-json-data.ts'; | ||
export default function localize(packName: string, key: string) { | ||
const targetLocale = process.env.TARGET_LOCALE; | ||
if (!targetLocale) { | ||
throw new Error('TARGET_LOCALE is not defined'); | ||
} | ||
const rawPack = getJsonData(packName); | ||
const pack = localizationPackSchema.parse(rawPack); | ||
return pack[key]![targetLocale]; | ||
} | ||
const localizationPackSchema = z.record(z.record(z.string().min(1))); |
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,49 @@ | ||
import type { Html } from 'mdast'; | ||
import { SKIP } from 'unist-util-visit'; | ||
|
||
import localize from '../localize.ts'; | ||
import type { MacroFunction, MacroNode } from '../types.ts'; | ||
import { wrappedNumberSchema, wrappedStringSchema } from '../validation.ts'; | ||
|
||
function parseArguments( | ||
value: string[], | ||
): [number, string | undefined, string | undefined] { | ||
if (value.length === 0 || !value[0]) { | ||
throw new Error('No arguments provided'); | ||
} | ||
return [ | ||
wrappedNumberSchema.parse(value[0]), | ||
value[1] ? wrappedStringSchema.parse(value[1]) : undefined, | ||
value[2] ? wrappedStringSchema.parse(value[2]) : undefined, | ||
]; | ||
} | ||
|
||
function macro(node: MacroNode): Html { | ||
let arguments_ = parseArguments(node.parameters); | ||
|
||
let link = 'https://datatracker.ietf.org/doc/html/rfc' + arguments_[0]; | ||
let text = ''; | ||
|
||
if (arguments_[1]) { | ||
text = ': ' + arguments_[1]; | ||
} | ||
|
||
if (arguments_[2]) { | ||
link = link + '#section-' + arguments_[2]; | ||
text = | ||
', ' + localize('L10n-Common', 'section') + ' ' + arguments_[2] + text; | ||
} | ||
|
||
return { | ||
type: 'html', | ||
value: `<a href="${link}">RFC ${text}</a>`, | ||
}; | ||
} | ||
|
||
const RFC: MacroFunction = (node, index, parent) => { | ||
const replacement = macro(node); | ||
parent.children[index] = replacement; | ||
return [SKIP, index]; | ||
}; | ||
|
||
export default RFC; |
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,20 @@ | ||
import { SKIP } from 'unist-util-visit'; | ||
|
||
import type { MacroFunction } from '../types.ts'; | ||
|
||
function macro() { | ||
return { | ||
type: 'html', | ||
value: `<abbr class="status-icon deprecated" title="Нерекомендоване. Не для використання в нових вебсайтах"> | ||
<span class="visually-hidden">Нерекомендоване</span> | ||
</abbr>`, | ||
}; | ||
} | ||
|
||
const deprecated_inline: MacroFunction = (_node, index, parent) => { | ||
const replacement = macro(); | ||
parent.children[index] = replacement; | ||
return [SKIP, index]; | ||
}; | ||
|
||
export default deprecated_inline; |
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