Skip to content

Commit

Permalink
Add full Russian language support
Browse files Browse the repository at this point in the history
  • Loading branch information
adipascu committed Jan 16, 2024
1 parent 8986774 commit f63c2ae
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
17 changes: 11 additions & 6 deletions src/Countdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import FONT_FAMILY from "./font";
import { GIT_HASH } from "./config";
import { calculateAgeLocal } from "./calculate-age";
import { colorBackground, colorPrimary, colorSecondary } from "./colors";
import { AGE, SOURCE_CODE } from "./translation";
import {
AGE,
COPY_LABEL,
SOURCE_CODE,
BIRTH_DAY_FORMAT,
AGE_COPIED,
AGE_COPY_FAILED,
} from "./translation";

const animationLoop = (cb: (time: DOMHighResTimeStamp) => void) => {
let handle: number;
Expand All @@ -18,8 +25,6 @@ const animationLoop = (cb: (time: DOMHighResTimeStamp) => void) => {
return () => cancelAnimationFrame(handle);
};

const COPY_LABEL = "Click to copy age to clipboard";

export default ({
birthDay,
openSettings,
Expand All @@ -42,9 +47,9 @@ export default ({
const ageString = `${largeAge()}.${smallAge()}`;
try {
await navigator.clipboard.writeText(ageString);
toast.success("Age copied to clipboard!");
toast.success(AGE_COPIED);
} catch (err) {
toast.error("Failed to copy age to clipboard!");
toast.error(AGE_COPY_FAILED);
}
};
return (
Expand Down Expand Up @@ -76,7 +81,7 @@ export default ({
color: colorSecondary(),
"margin-left": "4px",
}}
title={`Birthday: ${birthDay.toLocaleString()}`}
title={BIRTH_DAY_FORMAT(birthDay)}
>
<div onClick={copyAgeToClipboard}>{AGE}</div>
<IoSettingsSharp
Expand Down
5 changes: 3 additions & 2 deletions src/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createSignal } from "solid-js";
import { Temporal } from "temporal-polyfill";
import FONT_FAMILY from "./font";
import { colorBackground, colorPrimary, colorSecondary } from "./colors";
import { ENTER_BIRTHDAY, MOTIVATE } from "./translation";

export default ({
onBirthDay,
Expand All @@ -28,7 +29,7 @@ export default ({
"margin-bottom": "4px",
}}
>
Enter your Birthday
{ENTER_BIRTHDAY}
</label>
<input
autofocus
Expand Down Expand Up @@ -80,7 +81,7 @@ export default ({
e.currentTarget.style.backgroundColor = colorSecondary();
}}
>
Motivate
{MOTIVATE}
</button>
</div>
);
Expand Down
9 changes: 9 additions & 0 deletions src/translation/en.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
import type { Temporal } from "temporal-polyfill";

export const AGE = "Age";

Check failure on line 3 in src/translation/en.ts

View workflow job for this annotation

GitHub Actions / lint

exported declaration 'AGE' not used within other modules
export const SOURCE_CODE = "source code";

Check failure on line 4 in src/translation/en.ts

View workflow job for this annotation

GitHub Actions / lint

exported declaration 'SOURCE_CODE' not used within other modules
export const COPY_LABEL = "Click to copy age to clipboard";

Check failure on line 5 in src/translation/en.ts

View workflow job for this annotation

GitHub Actions / lint

exported declaration 'COPY_LABEL' not used within other modules
export const BIRTH_DAY_FORMAT = (birthDay: Temporal.PlainDate) =>

Check failure on line 6 in src/translation/en.ts

View workflow job for this annotation

GitHub Actions / lint

exported declaration 'BIRTH_DAY_FORMAT' not used within other modules
`Birthday: ${birthDay.toLocaleString()}`;
export const AGE_COPIED = "Age copied to clipboard!";

Check failure on line 8 in src/translation/en.ts

View workflow job for this annotation

GitHub Actions / lint

exported declaration 'AGE_COPIED' not used within other modules
export const AGE_COPY_FAILED = "Failed to copy age to clipboard!";

Check failure on line 9 in src/translation/en.ts

View workflow job for this annotation

GitHub Actions / lint

exported declaration 'AGE_COPY_FAILED' not used within other modules
export const ENTER_BIRTHDAY = "Enter your Birthday";

Check failure on line 10 in src/translation/en.ts

View workflow job for this annotation

GitHub Actions / lint

exported declaration 'ENTER_BIRTHDAY' not used within other modules
export const MOTIVATE = "Motivate";

Check failure on line 11 in src/translation/en.ts

View workflow job for this annotation

GitHub Actions / lint

exported declaration 'MOTIVATE' not used within other modules
13 changes: 11 additions & 2 deletions src/translation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let data;
switch (path) {
// TODO: remove workaround for TypeScript limitation
case "./en":
data = await import("./en");
data = await import("./ru");
break;
case "./ru":
data = await import("./ru");
Expand All @@ -32,4 +32,13 @@ switch (path) {
throw new Error("Language not supported");
}

export const { AGE, SOURCE_CODE } = data;
export const {
AGE,
SOURCE_CODE,
COPY_LABEL,
BIRTH_DAY_FORMAT,
AGE_COPIED,
AGE_COPY_FAILED,
ENTER_BIRTHDAY,
MOTIVATE,
} = data;
9 changes: 9 additions & 0 deletions src/translation/ru.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
import type { Temporal } from "temporal-polyfill";

export const AGE = "Возраст";
export const SOURCE_CODE = "исходный код";
export const COPY_LABEL = "Нажмите, чтобы скопировать возраст в буфер обмена";
export const BIRTH_DAY_FORMAT = (birthDay: Temporal.PlainDate) =>
`День рождения: ${birthDay.toLocaleString()}`;
export const AGE_COPIED = "Возраст скопирован в буфер обмена!";
export const AGE_COPY_FAILED = "Не удалось скопировать возраст в буфер обмена!";
export const ENTER_BIRTHDAY = "Введите свой день рождения";
export const MOTIVATE = "Мотивировать";

0 comments on commit f63c2ae

Please sign in to comment.