Skip to content

Commit

Permalink
Translation framework (KlimaDAO#43)
Browse files Browse the repository at this point in the history
* update package-lock files

* update gitignores

* i18n minimal

* Fixed newline add end of file in config files

* Trying to add a postinstall script to compile translations so the application deploys properly on Vercel

* Nicer localization menu

* Translated Home

* Save selected language in LocalStorage

* Translation: Stake page

* Updated translation files

* Optimized package.json dependencies

* Rebased with klima/staging

* Made files pretty.
Updated .prettierignore

* Commiting compiled translation files

* Fixed merge of .prettierignore

* Commited package-lock.json

Co-authored-by: Atmosfearful <atmosfearful@protonmail.com>
Co-authored-by: Bruno Ilponse <bruno.ilponse@gmail.com>
Co-authored-by: bilponse <bilponse@localhost.localdomain>
  • Loading branch information
4 people committed Jan 4, 2022
1 parent 43fa411 commit f8503a0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/components/views/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import { Trans } from "@lingui/macro";
import { locales, activate } from "lib/i18n";
import { i18n } from "@lingui/core";

import { Trans } from "@lingui/macro";
import { locales, activate } from "lib/i18n";
import { i18n } from "@lingui/core";

import styles from "./index.module.css";

type EIP1139Provider = ethers.providers.ExternalProvider & {
Expand Down
3 changes: 3 additions & 0 deletions app/components/views/Stake/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import T from "@klimadao/lib/theme/typography.module.css";
import styles from "./index.module.css";
import { Trans, t, defineMessage } from "@lingui/macro";
import { i18n } from "@lingui/core";
<<<<<<< HEAD
import { prettifySeconds } from "lib/i18n";
=======
>>>>>>> 80779ba... Translation framework (#43)

const WithPlaceholder: FC<{
condition: boolean;
Expand Down
27 changes: 27 additions & 0 deletions app/lib/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
import { i18n } from "@lingui/core";
import { en, fr } from "make-plural/plurals";
<<<<<<< HEAD
import enTime from "time-delta/locales/en";
import frTime from "time-delta/locales/fr";
import * as timeDelta from "time-delta";
import { prettifySeconds as prettifySecondsLib } from "@klimadao/lib/utils";
=======
>>>>>>> 80779ba... Translation framework (#43)

interface ILocales {
[locale: string]: {
plurals: (
n: number | string,
ord?: boolean
) => "zero" | "one" | "two" | "few" | "many" | "other";
<<<<<<< HEAD
time: any;
};
}
const locales: ILocales = {
en: { plurals: en, time: enTime },
fr: { plurals: fr, time: frTime },
=======
};
}
const locales: ILocales = {
en: { plurals: en },
fr: { plurals: fr },
>>>>>>> 80779ba... Translation framework (#43)
};

for (const key in locales) {
const locale = locales[key];
i18n.loadLocaleData(key, { plurals: locale.plurals });
<<<<<<< HEAD
timeDelta.addLocale(locale.time);
=======
//i18n.loadLocaleData("fr", { plurals: fr });
>>>>>>> 80779ba... Translation framework (#43)
}
async function load(locale: string) {
const { messages } = await import(`../locale/${locale}/messages.js`);
Expand All @@ -32,22 +47,31 @@ async function load(locale: string) {

/**
* Load messages for requested locale and activate it.
<<<<<<< HEAD
* Stores the choice in localestorage
=======
* This function isn't part of the LinguiJS library because there're
* many ways how to load messages from REST API, from file, from cache, etc.
>>>>>>> 80779ba... Translation framework (#43)
*/
async function activate(locale: string) {
load(locale);
window.localStorage.setItem("locale", locale);
}

<<<<<<< HEAD
/**
* Initializes locale (retrieve current locale fron localstorage if possible)
*/
=======
>>>>>>> 80779ba... Translation framework (#43)
function init() {
var locale = window.localStorage.getItem("locale") as string;
if (!Object.keys(locales).includes(locale)) locale = "en";
load(locale);
}

<<<<<<< HEAD
/**
* Localizes an amount of seconds
*/
Expand All @@ -56,3 +80,6 @@ function prettifySeconds(seconds: number) {
}

export { locales, activate, init, prettifySeconds };
=======
export { locales, activate, init };
>>>>>>> 80779ba... Translation framework (#43)

0 comments on commit f8503a0

Please sign in to comment.