-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Translation framework #43
Changes from 9 commits
0f48096
6f03e90
ecac179
99f845c
6b5dd34
19594f2
5c3325b
d51f2dc
44c2bf0
fd08669
8744f25
5f619a2
4555419
7b49582
9d9f993
b53df65
5d6c900
a5af52c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"next/babel", | ||
{ | ||
"preset-env": {}, | ||
"transform-runtime": {}, | ||
"styled-jsx": {}, | ||
"class-properties": {} | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
"macros" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"locales": [ | ||
"en", | ||
"fr" | ||
], | ||
"sourceLocale": "en", | ||
"catalogs": [ | ||
{ | ||
"path": "<rootDir>/locale/{locale}/messages", | ||
"include": [ | ||
"<rootDir>/" | ||
], | ||
"exclude": [ | ||
"**/node_modules/**" | ||
] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { i18n } from "@lingui/core"; | ||
import { en, fr } from "make-plural/plurals"; | ||
|
||
interface ILocales { | ||
[locale: string]: { | ||
plurals: (n: number | string, ord?: boolean) => "zero" | "one" | "two" | "few" | "many" | "other"; | ||
} | ||
} | ||
const locales: ILocales = { | ||
"en": { plurals: en}, | ||
"fr": { plurals: fr} | ||
}; | ||
|
||
for (const key in locales) { | ||
const locale = locales[key]; | ||
i18n.loadLocaleData(key, { plurals: locale.plurals }); | ||
//i18n.loadLocaleData("fr", { plurals: fr }); | ||
} | ||
async function load(locale: string) { | ||
const { messages } = await import(`../locale/${locale}/messages.js`); | ||
i18n.load(locale, messages); | ||
i18n.activate(locale); | ||
} | ||
|
||
/** | ||
* Load messages for requested locale and activate it. | ||
* 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. | ||
*/ | ||
async function activate(locale: string) { | ||
load(locale); | ||
window.localStorage.setItem("locale", locale); | ||
} | ||
|
||
function init() { | ||
var locale = window.localStorage.getItem("locale") as string; | ||
if (!Object.keys(locales).includes(locale)) locale = "en"; | ||
load(locale); | ||
} | ||
|
||
export {locales, activate, init}; | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
msgid "" | ||
msgstr "" | ||
"POT-Creation-Date: 2021-12-10 22:51+0100\n" | ||
"Mime-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=utf-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"X-Generator: @lingui/cli\n" | ||
"Language: en\n" | ||
"Project-Id-Version: \n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"PO-Revision-Date: \n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"Plural-Forms: \n" | ||
|
||
#: components/views/Home/index.tsx:325 | ||
msgid "footer.blog" | ||
msgstr "blog" | ||
|
||
#: components/views/Home/index.tsx:326 | ||
msgid "footer.community" | ||
msgstr "community" | ||
|
||
#: components/views/Home/index.tsx:324 | ||
msgid "footer.docs" | ||
msgstr "docs" | ||
|
||
#: components/views/Home/index.tsx:323 | ||
msgid "footer.home" | ||
msgstr "home" | ||
|
||
#: components/views/Home/index.tsx:235 | ||
msgid "header.connectedto" | ||
msgstr "You are connected to" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could probably answer this question by reading the docs but, Or is this auto-generated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to change it only in the |
||
|
||
#: components/views/Home/index.tsx:273 | ||
msgid "header.welcome" | ||
msgstr "Welcome to the Klima dApp. Bond carbon to buy KLIMA. Stake KLIMA to earn interest." | ||
|
||
#: components/views/Home/index.tsx:249 | ||
msgid "menu.bond" | ||
msgstr "BOND" | ||
|
||
#: components/views/Home/index.tsx:252 | ||
msgid "menu.info" | ||
msgstr "INFO" | ||
|
||
#: components/views/Home/index.tsx:240 | ||
msgid "menu.redeem" | ||
msgstr "REDEEM" | ||
|
||
#: components/views/Home/index.tsx:243 | ||
msgid "menu.stake" | ||
msgstr "STAKE" | ||
|
||
#: components/views/Home/index.tsx:246 | ||
msgid "menu.wrap" | ||
msgstr "WRAP" | ||
|
||
#: components/views/Home/index.tsx:286 | ||
msgid "usermenu.changelanguage" | ||
msgstr "Language" | ||
|
||
#: components/views/Home/index.tsx:280 | ||
msgid "usermenu.connect_wallet" | ||
msgstr "CONNECT WALLET" | ||
|
||
#: components/views/Home/index.tsx:283 | ||
msgid "usermenu.disconnect_wallet" | ||
msgstr "DISCONNECT WALLET" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably fine for now but it raised a question for me:
Generally speaking, is it better to use interpolation for strings like these?
What does that look like in lingui? in other libs I used its something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the rationale being, in another language the noun
testnet
might not appear at the endThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can't use interpolation in translations I would say this should be a deal-breaker for lingui.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interpolation is definetly better and possible with lingui. I was just being lazy. But I am not sure with the
<stong>
tag in between...