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

Merged
merged 12 commits into from
May 13, 2025

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!

@nvuillam
Copy link
Member

@matheus-delazeri i'm sorry i forgot about this PR ^^

Please can you update .cspell.json to add the exceptions ?

( look for string "unknown word" in cspell output log)

@matheus-delazeri
Copy link
Contributor Author

Hi @nvuillam, how are you? No problem, I've forgotten about it too, rembered this friday when I had to use the command XD

I've made the changes to the .cspell.json file :)

Copy link
Member

@nvuillam nvuillam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the update about doc gen and i'll merge :)

@matheus-delazeri
Copy link
Contributor Author

matheus-delazeri commented May 13, 2025

Hey @nvuillam! I've made the changes :)
Thanks a lot!

@matheus-delazeri matheus-delazeri requested a review from nvuillam May 13, 2025 18:02
@nvuillam nvuillam merged commit 814c76d into hardisgroupcom:main May 13, 2025
2 checks passed
@nvuillam
Copy link
Member

@matheus-delazeri released :)

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