Skip to content

Feat: new command "custom-label-translations" #1138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

matheus-delazeri
Copy link
Contributor

@matheus-delazeri matheus-delazeri commented Mar 24, 2025

Hey! 😃

This new command allows to extract the translations of:

  • selected Custom Labels;
  • a specific LWC.

It generates a translation file (*.translation-meta.xml) for each language already retrieved in the current project. These files will contain only the specified Custom Labels, making it easier to translate or deploy them to another org if needed. The files will be placed in the extracted-translations folder.

Example 1 - Extract from specific Custom Labels

Assuming I have this translations files (retrieved from my Org):

  • pt_BR.translation-meta.xml 🇧🇷
<?xml version="1.0" encoding="UTF-8"?>
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
    <customLabels>
        <label>Teste</label>
        <name>Test</name>
    </customLabels>
    <customLabels>
        <label>Olá</label>
        <name>Hello</name>
    </customLabels>
</Translations>
  • es.translation-meta.xml 🇪🇸
<?xml version="1.0" encoding="UTF-8"?>
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
   <customLabels>
       <label>Teste</label>
       <name>Test</name>
   </customLabels>
   <customLabels>
       <label>Hola</label>
       <name>Hello</name>
   </customLabels>
</Translations>

And I want to only change/deploy the Hello Custom Label. I can execute the command:

sf hardis misc custom-label-translations --label Hello

The result would be the following translation files, at extracted-translations/):

  • pt_BR.translation-meta.xml 🇧🇷
<?xml version="1.0" encoding="UTF-8"?>
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
    <customLabels>
        <label>Olá</label>
        <name>Hello</name>
    </customLabels>
</Translations>
  • es.translation-meta.xml 🇪🇸
<?xml version="1.0" encoding="UTF-8"?>
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
   <customLabels>
       <label>Hola</label>
       <name>Hello</name>
   </customLabels>
</Translations>

Note: It's possible to extract more than one Custom Label at once delimitating them by comma.

Example 2 - Extract from LWC

Assuming we have a LWC that imports two Custom Labels:

import error from '@salesforce/label/c.error';
import success from '@salesforce/label/c.success';

export default class MyComponent extends LightningElement {
     ...
}

We can run the following command to extract the Custom Labels used, making it easier to translate the labels specific to this component:

sf hardis misc custom-label-translations --lwc MyComponent

This way, the following files will be generated, at extracted-translations/MyComponent-{timestamp}/:

  • pt_BR.translation-meta.xml 🇧🇷
<?xml version="1.0" encoding="UTF-8"?>
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
    <customLabels>
        <label>Erro</label>
        <name>error</name>
    </customLabels>
    <customLabels>
        <label>Sucesso</label>
        <name>success</name>
    </customLabels>
</Translations>
  • es.translation-meta.xml 🇪🇸
<?xml version="1.0" encoding="UTF-8"?>
<Translations xmlns="http://soap.sforce.com/2006/04/metadata">
   <customLabels>
       <label>Error</label>
       <name>error</name>
   </customLabels>
   <customLabels>
       <label>Éxito</label>
       <name>success</name>
   </customLabels>
</Translations>

Let me know if any adjustment should be done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants