Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Add a language format style for i18n #59

Open
alpay opened this issue Aug 14, 2020 · 1 comment
Open

Add a language format style for i18n #59

alpay opened this issue Aug 14, 2020 · 1 comment

Comments

@alpay
Copy link

alpay commented Aug 14, 2020

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.

@manzinello
Copy link
Owner

Hi Alpay! Sorry for the delay, I was on vacation! The problem is clear and I really like your second proposal, I think that it is the best and more extendable solution for the problem. The problem in this specific language (and thank you so much to have raised this question) is the order but maybe with another language we will have different problems (maybe not only the order!), I think that your template proposal is perfect.

Well the problem is present because in the HTML there is a strong element (for example open in **Telegram**), if the strings in the JSON had been "open in Telegram" completely there would not be the problem of the order! At the moment I don't want to remove this strong element, so your templating solution is what I really want to add in mailgo, thank you so much for your contribution and for the question of the i18n for different languages (that I really don't know).

I surely will work on this! Maybe do you want to submit a PR? Now I have to work also on other things in mailgo, so if you want to be a contributor feel free to apply your awesome solution.

manzinello added a commit that referenced this issue Sep 22, 2020
manzinello added a commit that referenced this issue Dec 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants