jekyll-multiple-languages-plugin icon indicating copy to clipboard operation
jekyll-multiple-languages-plugin copied to clipboard

Its not working if translation key has a root key

Open HatemKhattab opened this issue 5 years ago • 5 comments

Hi

I used localeapp to pull my translation, it adding root key to en.yml like this

en: key_1: xx key_2: xx

is there away to make {%t key_1%} work if en.yml has a root key?

HatemKhattab avatar Nov 08 '19 09:11 HatemKhattab

Is key_1 and key_2 indented? Not sure if it was just a formatting error when creating this issue. If this is the case, then you'd access that variable as such: {% t 'en.key_1' %}

hanniabu avatar Nov 12 '19 19:11 hanniabu

Hej Hani and thanks for your reply, its indented, its work like {% t 'en.key_1' %} but it not dynamic to chose the right translation file depends on the site language , I mean if the page is mysite.com/en ===> english translation or mysite.com/sv ==> swedish translation in this way it is enough to write {% t key_1 %}

HatemKhattab avatar Nov 12 '19 22:11 HatemKhattab

Hi @HanniAbu and thanks for your reply, its idented, i want to bring the wright translation dynamically if mysite.com/en ===> english translation, if mysite.com/sv ===> swedish translation

in this way i just wirite {% t key_1 %}

HatemKhattab avatar Nov 12 '19 22:11 HatemKhattab

I see, I haven't tried myself to see if it works, but something like this might do the trick:

Add this to the top of each page:

{% assign t = site.translations[site.lang].[site.lang] %}

Use in the page like this:

The value of Key 1 is {{ t.key_1 }} and the value of Key 2 is {{ t.key_2 }}.

hanniabu avatar Nov 12 '19 23:11 hanniabu

it looks good @HanniAbu or maybe something like {%t site.lang.key_1%}

HatemKhattab avatar Nov 12 '19 23:11 HatemKhattab