Skip to content

Commit

Permalink
test: add support for split translations
Browse files Browse the repository at this point in the history
  • Loading branch information
strbit committed Sep 12, 2024
1 parent e039713 commit 698588e
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { join } from "./deps.ts";

export function makeTempLocalesDir() {
const dir = Deno.makeTempDirSync();
Deno.writeTextFileSync(
join(dir, "en.ftl"),
`hello = Hello!

const englishTranslation = `hello = Hello!
greeting = Hello, { $name }!
Expand All @@ -21,11 +20,9 @@ language =
.hint = Enter a language with the command
.invalid-locale = Invalid language
.already-set = Language is already set!
.language-set = Language set successfullY!`,
);
Deno.writeTextFileSync(
join(dir, "ru.ftl"),
`hello = Здравствуйте!
.language-set = Language set successfullY!`;

const russianTranslation = `hello = Здравствуйте!
greeting = Здравствуйте, { $name }!
Expand All @@ -34,7 +31,7 @@ cart = Привет { $name }, в твоей корзине {
[0] нет яблок
[one] {$apples} яблоко
[few] {$apples} яблока
*[other] {$apples} яблок
*[other] {$apples} яблок
}.
checkout = Спасибо за покупку!
Expand All @@ -43,7 +40,26 @@ language =
.hint = Отправьте язык после команды
.invalid-locale = Неверный язык
.already-set = Этот язык уже установлен!
.language-set = Язык успешно установлен!`,
);
.language-set = Язык успешно установлен!`;

function writeNestedFiles() {
const nestedPath = join(dir, "/ru/test/nested/");
const keys = russianTranslation.split(/\n\s*\n/);

Deno.mkdirSync(nestedPath, { recursive: true });

for (const key of keys) {
const fileName = key.split(" ")[0] + ".ftl";
const filePath = join(nestedPath, fileName);

Deno.writeTextFileSync(filePath, key);
}
}

// Using normal, singular translation files.
Deno.writeTextFileSync(join(dir, "en.ftl"), englishTranslation);
// Using split translation files.
writeNestedFiles();

return dir;
}

0 comments on commit 698588e

Please sign in to comment.