mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: some period translations
This commit is contained in:
1 parent
267f23cad8
commit
adad668157
24 files changed
+1309
-1216
No files matched your search
@@ -5,9 +5,10 @@ export function translator(localeRaw: Locale) {
|
||||
const locale = locales.includes(localeRaw) ? localeRaw : Locale.EnglishUS;
|
||||
const strings = translations[locale];
|
||||
|
||||
function translate(path: string): string {
|
||||
function translate(path: string, literals?: string[]): string {
|
||||
const pathArray = path.split('.');
|
||||
let fragment = strings;
|
||||
let resolvedString: string;
|
||||
|
||||
for (const pathItem of pathArray) {
|
||||
if (typeof fragment === 'string') {
|
||||
@@ -33,14 +34,26 @@ export function translator(localeRaw: Locale) {
|
||||
}
|
||||
|
||||
if (typeof fragment === 'string') {
|
||||
return fragment;
|
||||
resolvedString = fragment;
|
||||
} else if (fragment.$) {
|
||||
return fragment.$!;
|
||||
resolvedString = fragment.$!;
|
||||
} else {
|
||||
throw new Error(
|
||||
`Unresolved tree ending for "${path}" in locale "${locale}"`,
|
||||
);
|
||||
}
|
||||
|
||||
if (literals) {
|
||||
const chunks = resolvedString.split('%s');
|
||||
let embeddedString = '';
|
||||
|
||||
chunks.forEach((chunk, index) => {
|
||||
if (index !== 0) embeddedString += literals[index - 1];
|
||||
embeddedString += chunk;
|
||||
});
|
||||
}
|
||||
|
||||
return resolvedString;
|
||||
}
|
||||
|
||||
function t(paths: TemplateStringsArray, ...embeds: string[]) {
|
||||
|
||||
Reference in new issue
Block a user