5

I'm developing a lightning 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 where I install the beta of my package.
In visualforce translations always work.
I'm using the standard lightning component syntax to access custom labels like below.

<lightning:button  label="{!$Label.namespace.myCustomLabel}" onclick="{!c.myFunction}"/>
  • did you package the translation components? – Itai Shmida Dec 4 '16 at 8:03
  • @Itai yes. "Language Translation" component is listed in my package. Custom label translations work everywhere except the lightning component.. – Vladimir Romanov Dec 5 '16 at 8:18
  • 2
    I struck what was superficially the same problem recently. When translating strings the changes did not appear in the lightning components in the UI, although I could see them in Apex. I found that logging out and logging in again (or opening a session in another browser) resulted in the translated strings appearing, suggesting they're fairly aggressively cached in the UI. Potentially not the same issue as you were experiencing 2 years ago, but maybe this will be useful to someone – James Dec 17 '18 at 16:49
3

My current workaround for this is to add a server side action (custom labels work in apex) 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 all custom labels anyway in order to include them in a managed package)

bottleneck: You have to make sure you load labels before doing anything else. If you have nested structure of your components and you load labels only once in the root component -> you have to manage loading of custom labels to insure the labels attribute is accessed only when it's populated.

Apex controller:

@AuraEnabled
public static Map<String,String> getCustomLabelMap(){
    Map<String,String> customLabelMap = new Map<String, String>();
    customLabelMap.put('MyCustomLabel1',Label.MyCustomLabel1);
    customLabelMap.put('MyCustomLabel2',Label.MyCustomLabel2);
    return customLabelMap;
}

Lightning Component:

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="LABEL" type="Map" access="private"/>

<lightning:button label="{!v.LABEL.MyCustomLabel1}" onclick="{!c.myFunction}" />

Lightning Component Controller:

({
    doInit: function (component, event, helper) {
        var action = component.get("c.getCustomLabelMap");
        action.setCallback(this, function (response) {
                var LABEL = response.getReturnValue();
                component.set("v.LABEL",LABEL);
        });
        $A.enqueueAction(action);
    },
    myFunction: function () {
        //myFunction
    }
})
0

Enabling the Translation Workbench in the Subscriber Org fixed the issue for us.

Please not that Labels returned from Apex work without Translation workbench - so I assume, there is something off.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.