How to Handle Translations in 2GP Package?

Spread the love

Question

I am working on a second-generation managed package and need to add translations for some Lightning Web Components (LWCs) into German. The translations are implemented using Custom Labels, stored in CustomLabels.labels-meta.xml, and the German translations are stored in de.translation-meta.xml inside the translations folder.

Before creating a new beta version of the package, I added both the labels and translations folders to the project. However, when I run the following command to create the beta version:

sf package version create --package "App Name" --code-coverage --wait 10 -v dev-hub-alias --installation-key-bypass

I encounter the following error:

Version create.... Create version status: Error

(1) de: Not available for deploy for this organization

If I remove the translations folder, the beta version is created successfully.

It appears that the temporary org created by Salesforce for package version creation does not have the Translation Workbench feature enabled. Since this feature is required to handle translations, the process fails. I suspect the temporary org’s default settings are missing the necessary configuration.

Here is the sfdx-project.json file used for the package:

{
  "packageDirectories": [
    {
      "path": "force-app",
      "default": true,
      "package": "App Name",
      "versionName": "ver 1.5",
      "versionNumber": "1.5.0.NEXT",
      "versionDescription": "",
      "ancestorId": "HIGHEST"
    }
  ],
  "namespace": "test_namespase150",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "58.0",
  "packageAliases": {
    "First Name@1.4.0-1": "04t07000000DCsOAVQ",
    "First Name@1.4.0-2": "04t07000000DCtWADI",
    "First Name@1.5.0-1": "04tJ6000000Y0efIPC"
  }
}

Is there a way to configure the package creation process to include the necessary settings for enabling Translation Workbench in the temporary org?

Answer

Yes, you can address this issue by using the --definition-file parameter available in the sf package version create command. This parameter allows you to specify a definition file (similar to a scratch org definition file) containing the required features and settings for the temporary org used during package version creation.

When Salesforce processes the package version create command, it creates a temporary org in the background to validate, compile, and freeze your metadata. By default, this org does not have the Translation Workbench feature enabled, which is why the process fails when translations are included. The --definition-file parameter ensures that the temporary org has the same features and settings as your development environment.

Here’s how to resolve the issue:

Step 1: Create a Definition File

Create a file named package-scratch-def.json with the following content. This enables the Translation Workbench feature:

{
  "orgName": "Temporary Org",
  "edition": "Developer",
  "features": [],
  "settings": {
    "languageSettings": {
      "enableTranslationWorkbench": true
    }
  }
}

This file mimics the configuration of a scratch org but is tailored for the temporary org used during package version creation.

Step 2: Use the Definition File in the Package Version Command

Update your package creation command to include the --definition-file parameter and point it to the newly created definition file:

sf package version create --package "App Name" --code-coverage --wait 10 -v dev-hub-alias --definition-file path/to/package-scratch-def.json --installation-key-bypass

This command ensures that the temporary org created during the process has Translation Workbench enabled, allowing the translations to be successfully processed.

Why Is the Definition File Important?

The temporary org created for package versioning is disposable and does not inherit settings from your development org. By specifying a definition file, you can define the org’s configuration, ensuring that it has all the necessary features and settings required for your package’s metadata to work. Without this file, any feature dependency, like Translation Workbench, will cause errors because the temporary org uses minimal settings by default.

Alternative Solution

If you cannot use the --definition-file parameter, you can take a manual approach as a workaround. Remove the translations folder during the package version creation process and deploy the translations manually to target orgs after enabling Translation Workbench in those orgs. To do this:

  1. Create the package without the translations folder.
  2. Enable Translation Workbench in the target org.
  3. Deploy the translations folder using the sf project deploy start command.

However, this approach is less efficient and introduces the risk of inconsistencies. It is recommended to use the --definition-file approach for a seamless and automated process.

Using the definition file ensures that your package creation process is smooth, consistent, and aligned with your development environment settings. This method avoids the manual steps and reduces the chances of errors.

Real-Time Project-Based Salesforce Training to Kick Start Your Career

Our Salesforce Course is thoughtfully designed to provide a comprehensive understanding of the Salesforce platform, equipping you with the vital skills needed to thrive in the CRM industry. The program covers important modules like Salesforce Admin, Developer, and AI, combining theoretical knowledge with hands-on application. By engaging in real-world projects and practical tasks, you’ll develop the expertise to address complex business challenges with confidence using Salesforce solutions. Our expert instructors ensure you gain both technical skills and industry-specific insights to excel within the Salesforce ecosystem.

In addition to gaining technical knowledge, our Salesforce training in Mumbai offers personalized coaching, exam preparation support, and interview guidance to enhance your career prospects. You’ll have access to in-depth study materials, real-life project experience, and ongoing support throughout the course. Upon completing the program, you’ll be fully prepared for certification exams and equipped with the problem-solving abilities and practical skills that employers highly seek. Start your Salesforce career journey with us and unlock limitless career opportunities. Sign up for a Free Demo now!

Open Chat
1
Dear Sir/Madam
How can I help you?