Hi! I saw the project on Twitter and immediately fell in love with it :)
Problem
I want to translate i18n strings to my native language (Turkish) but the grammar difference of my language with other latin languages makes it really hard.
Example 1
For English: 'open in Telegram' is coded like this -> open_in_ + telegram
Translation for Turkish should be: "Telegram ile aç". Need to be coded like this. -> telegram + open_in_
Example 2
For English: 'call as default' is coded like this -> call + _as_default
Translation for Turkish should be: "Varsayılan ile ara". Need to be coded like this. -> _as_default + call
Proposal
As you can see from the examples, different languages might need different formatting for proper translations.
In order to fix this problem, I propose 2 different solutions:
1. Add a boolean config value to reverse order
We can add a boolean flag to every language config like this:
// i18n/i18n.json
"en": {
"open_in_": "open in ",
"is_reverse_order": false,
// ...
},
"tr": {
"open_in_": "ile aç ",
"is_reverse_order": true,
// ...
},
Then, we can create text nodes conditionally by checking flag like this:
// src/mailgo.ts
gmail = createElement(aHTMLTag) as HTMLLinkElement;
let openTextNode = createTextNode(strings.open_in_ || defaultStrings.open_in_);
let gmailSpan: HTMLElement = createElement(spanHTMLTag);
gmailSpan.appendChild(
createTextNode(strings.gmail || defaultStrings.gmail)
);
if(strings.is_reverse_order) {
gmail.append(gmailSpan, openTextNode)
}
else {
gmail.append(openTextNode, gmailSpan)
}
2.Implement string template feature
We can add a template variable (like template literals) in order to allow every language decide how their strings should look:
// i18n/i18n.json
"en": {
"open_in_": "open in ",
"telegram": "telegram",
"open_in_template": "${open_in_} ${telegram}",
// ...
},
"tr": {
"open_in_": "ile aç ",
"telegram": "telegram",
"open_in_template": "${telegram} ${open_in_}",
// ...
},
What do you think about the problem and the proposals? I can also help you to implement this feature. Waiting for your answer. Cheers.