2

I created a lightning web component(LWC) with custom labels.
And I also set translation with these labels. (My default lang is Japanese, and translation is English).

But I found these labels is always showing itself in English, even though lang and locale is set to ja and ja_JP correctly.

This behavior is same on LightningApp and Visualforce with lightningOut.

How can I get the correctly tranlated labels?

Here is sample code and meta.

force-app/main/default/lwc/labelTest/labelTest.js

import { LightningElement, track } from 'lwc';
import translate from '@salesforce/label/c.translate';
import lang from '@salesforce/i18n/lang';
import locale from '@salesforce/i18n/locale';

export default class LabelTest extends LightningElement {
  @track translate = translate;
  @track info = {
    lang,
    locale,
  }
}

force-app/main/default/labels/CustomLabels.labels-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<CustomLabels xmlns="http://soap.sforce.com/2006/04/metadata">
    <labels>
        <fullName>translate</fullName>
        <language>ja</language>
        <protected>true</protected>
        <shortDescription>翻訳</shortDescription>
        <value>翻訳する</value>
    </labels>
</CustomLabels>

force-app/main/default/translations/en_US.translation-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
    <customLabels>
        <label>Translate</label>
        <name>translate</name>
    </customLabels>
...
</Translations>

force-app/main/default/translations/ja.translation-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
    <customLabels>
        <label><!-- 翻訳する --></label>
        <name>translate</name>
    </customLabels>
...
</Translations>

This gives me below. enter image description here

Please help me!

  • 1
    I did notice you have a trailing comma after "locale" but it's inconsequential when I run the code (stylistically incorrect though). I tried with default org as EN and JP with my own user settings in both contexts. It showed the JP / EN translations appropriately. This may be something germane to your org as I cannot repro. – jmdohn Jul 3 at 2:37
  • Thank you @jmdohn. – tatsuya kanemoto Jul 3 at 3:34
0

I did try and error after this post.
I solved this somewhat.

While in my question, jp translation is commented out as default.
However I changed it to the same as the custom label value (looks like below), I got correct label.

<?xml version="1.0" encoding="UTF-8"?>
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
    <customLabels>
        <label>翻訳する</label>
        <name>translate</name>
    </customLabels>
...
</Translations>

But I think this behavior is different from other salesforce services.

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.