8

I have a Lightning Community for different countries. Have components w/ custom labels(Language : English). Labels have a German Translations(German, active). I use labels in tags:

etc.

I see only English equivalent of a label, but I need to see this in German.

For VF SF has: And this translates labels.

Do we have something like this in Lightning? Or how can I apply Translations to Custom label?

Any help will be appreciated! Thank you!

1
  • It is possible to use Site.com preference: Languages->Default Site Language-> Choose German. But Is there another way to translate Custom labels (Change Community User data, change lightning components? Commented Nov 1, 2016 at 12:04

6 Answers 6

3

Probably this is a Salesforce bug. I have a similar problem. I'm developing a component as part of managed package. Translations work when I'm inside the development org, but I get only English values when using the component in my test org.

My workaround for this is to add a server side action that would return a map of all the custom labels used in the component and then set it as an attribute of type "Map". (You need to reference in apex or visualforce all labels anyway in order to include them in a managed package)

I don't know if your problem is the same so I submitted another question and sample code for the workaround here https://salesforce.stackexchange.com/a/150840/27814

2

How about this?

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject_describe.htm#apex_methods_system_sobject_describe

If there is a translation already present in Salesforce, you can look it up with a describe function, which then translates it to your locale settings (or somebody else's, whoever is using it).

I'm going to be working with this as well, as I'm currently developing an app that supposedly should also have multi-language support (have to discuss with my supervisor if and which languages, but as a start he sent me this link).

(To be clear: this is APEX code, so you do need an APEX controller attached to your lightning component)

2

Options to translate community were applied:

  1. Translation Workbench was used to translate picklists values.
  2. Site.com default community language was switched to German.
  3. Optionally able to implement and use URL parameter.

In case Community builder Admin have to put Label value to component parameter/attribute section: 1. Have to use declaration:

$Label.c.XXX_Label_Name

Where to use
2. Component .js controller:
Have:

< design:attribute name="headerName" label="Header Name"/>
< aura:attribute name="headerName" type="String" />


On Init: 2.1 OR 2.2.

2.1

var headerName = cmp.get("v.headerName")
var labelRef = $A.getReference(headerName)
cmp.set("v.headerName", labelRef)

2.2 Commented label name is a must

//$Label.c.MAH_Contact_Us
cmp.set("v.headerName", $A.get(cmp.get("v.headerName")))

Takes time to load it.

Thanks a lot for the help and ideas!

1

If this is a custom lightning component, all labels can be custom attribtes

{
initTranslations:function(component, event, helper){
   //language dependent
   if($Locale.langLocale==='de_DE'){
      var i18n ={"my_expense": "my expense"};
   }
   component.set("v.i18n", i18n)
}
}

<aura:attribute name="i18n" type="object"/>
<ui:inputText label="{v.i18n.my_expense}" required="true"/>

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/expr_locale_value_provider.htm

1
  • Thank you for your reply! However I needed translations from custom label. Please find answer on separate answer. Commented Feb 3, 2018 at 19:21
0

This should work out of the box. If you go to your custom label, you can add a translation to it (there is a translation related list under your label). Then using {!$Label.c.labelName} in your Lightning Component will get the correct label according to the connected user language.

1
0

What worked for me: adding an explicit translation for the default language. I had a label in my default language with name and value 'XYZ' and an English translation 'ABC'. Even though I had selected my default language while using my LWC, I still got the English translation 'ABC' in my LWC.

I then added a translation for the default language, with value 'XYZ' (obviously). And now my LWC was displaying 'XYZ'.

So LWC seems to rely on explicit translations for all languages for which you want to see translated values.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .