Hello, I want to add a new language to a existing ...
# extensions
c
Hello, I want to add a new language to a existing rancher plugin. What should I do? Just add a new locale file in L10n folder ?
s
Partly. you would need to add that language as well with
plugin.addLocale('en-uk', 'UK English');
For an example see https://github.com/rancher/ui-plugin-examples/tree/main/pkg/uk-locale
👍 2
if it's a language already known to rancher though, yes just drop in that l10n file to provide translates for existing strings
c
Thanks for the reply. I want to add Chinese language to Rancher harvester plugin . I saw Rancher UI already have zh-hans.yaml file in "shell/assets/translations/" and "/pkg/harvester-manager/l10n/". Does that mean the language is already known to rancher. I tried to add a zh-hans.yaml in harvster L10n. but it didnot work when I choose Chinese。
s
If you're adding localisation for zh-hands all you should need is that
<url extension>/l10n/zh-hands.yaml
file. Can you provide a link to your extension?
c
OK, I will push it into a repo.
image.png
s
That looks correct. Are you sure your version of the harvester extension is being used?
c
OK, If I don't miss modifing something I will try again. BTW, I read the extension doc about localization, what's the difference between
./pkg/<extension-name>/l10n and  assets/translations dir
?
s
unfortunately that stopped me linked there. it's mixed two locations up, one for extensions one for core ui. i've created an issue to fix https://github.com/rancher/dashboard/issues/14334
@busy-ability-54059 extensions localisation files should definitely be in
pkg/<ext>/l10n/<locale>.yaml
right?
b
that’s correct @stocky-account-63046. If you want to add a new locale via an extension you have to use the
addLocale
method like https://github.com/rancher/ui-plugin-examples/blob/main/pkg/uk-locale/index.ts#L13, but the file should still live in
l10n
folder
In @crooked-potato-83138’s example, adding the file should be enough, I reckon. The locale is already registered by default on Dashboard
c
Thank you for confirmation @busy-ability-54059 @stocky-account-63046
🫡 1
I run the deveployment tools in Edge browser. And I found that the zh-hans.yaml is not loaded. I modify the en-us.yaml. It works. How the locale file is packaged into the extension?
image.png
@busy-ability-54059
b
Let me have a try first…
@busy-ability-54059
b
I just gave it a try with your fork+branch with the following yaml, for a file I created in
l10n/zh-hans.yaml
in your extension.
Copy code
landing:
  landingPrefs:
    title: SOME-TITLE-FROM-ZH-HANS
and I was able to see the change on a translation - in this case the home screen. I also did a build and developer load and everything worked fine. Are you sure you’re applying the translations with the correct yaml hierarchy? Because I can’t find any problem with it.
c
Did you mean the home screen for the Harvester extension? Was the zh-hans.yaml in plugin loaded into the browser correctly?
b
I meant the actual homepage on Rancher… The principle is the same. I even did something more complete: I picked up your extension fork again, added a translation for a string that is only present in another extension (Elemental) to see if the whole translation mechanism and override capabilities were good, and it worked just fine - the original translation for that button on Elemental is only present on the
l10n
file in Elemental extension (check screenshots). I just added a
zh-hans.yaml
file with the correct yaml structure to override the translation I wanted. This definitively proves that the mechanism is working fine.
c
OK. I got it. So the translation string is in a big global tree. There is not package isolation.
👍 1