[SalesForce] How to include translations in the managed package

I want to include translations in my managed package so that all the text in my managed package matches the user's locale if I included a translation for that locale.

What I have done so far:

So far I have put a few custom labels on an aura component in my package as a test, then I enabled translation workbench (via setup->user interface->translation workbench->translation language settings) and added in a translation on a locale for one of my custom labels and switched the current locale to that language using profilepic->settings->my personal information->language & time zone->language

Everything translated like a charm!

While this is great, I wanted to make sure that I could reproduce on a new scratch org and pull it into my source code, so I did a sfdx force:source:pull and it appropriately updated my CustomLabels.labels-meta.xml file and gave me a new translation file: fr.translation-meta.xml (my test language was French)

I then tried to create a new scratch org with these changes to my code, but I got the following errors:

─────  ───────────────────────────────────────────────────────────────────────────────  ──────────────────────────────────────────────────────────────
Error  force-app/main/default/translations/fr.translation-meta.xml                      Not available for deploy for this organization
Error  force-app/main/default/aura/myWidget/myWidget.cmp                                Label my_label_name cannot be found in namespace c.

I don't know why I am getting the first error at all.

Here is what I am going to try for the second error: I am currently working with my sysadmins to connect the production namespace that my package uses to my devhub. After that is set up, I plan on setting the namespace in my sfdx-project.json file (see below) from blank to my production namespace. After I do that, I will change my label references from {! $Label.c.my_label_name } to {! $Label.mynamespace.my_label_name } instead.

Current sfdx-project.json, for reference:

{
    "packageDirectories": [{
        "path": "force-app/main",
        "default": true
    }],
    "namespace": "",
    "sfdcLoginUrl": "https://login.salesforce.com",
    "sourceApiVersion": "46.0"
}

Am I approaching this correctly to include translations in my managed package? Can you help me understand what I am doing wrong?

(cross posted to https://developer.salesforce.com/forums/#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Lightning&criteria=OPENQUESTIONS&id=9062I000000XumFQAS)

Best Answer

In order to include translations in your managed package, you just need to specify them in the package manifest. This is the same process as adding a custom field, object, class, etc.

In order to deploy translations to a Scratch Org, the Translation Workbench must first be enabled. To do this, include the following settings in your org configuration file:

  "settings": {
    "languageSettings": {
      "enableTranslationWorkbench": true
    }
  }

This file must be specified when creating a scratch org using the -f option, as in:

sfdx force:org:create -s -a myscratchorg -f config/my-scratch-config.json -u devhuborg
Related Topic