Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Translations using Custom Labels and Metadata

    Translations using Custom Labels and Metadata

    July 29, 2024

    Handling translations in Salesforce can significantly enhance the user experience by presenting content in multiple languages. To implement this feature, you need to leverage Salesforce’s Custom Labels and Custom Metadata Types in conjunction with Lightning Web Components (LWC). In this blog, I’ll guide you through the process of setting up translations using these tools. Additionally, I will provide sample code, describe the expected output, and highlight common issues faced during implementation.

    Setting Up Custom Labels for Translations

    Custom Labels in Salesforce allow you to store text values that can be translated into different languages. This feature is crucial for maintaining consistency in user interfaces across various locales. Furthermore, by utilizing Custom Labels, you ensure that users receive a cohesive experience, regardless of their preferred language. As a result, it enhances usability and improves user satisfaction across diverse regions.

    Steps to Create Custom Labels:

    Navigate to Custom Labels: Go to Setup in Salesforce. Search for Custom Labels and click on it.
    Create New Labels: Click on New Custom Label. Enter a name (e.g., WELCOME_MESSAGE) and a default value (e.g., Welcome to our application!). Save your changes. Repeat for each label, ensuring that translations are added for different languages.

    Creating Custom Metadata Types

    Custom Metadata Types allow for the storage of configuration data that can be managed without code changes. Additionally, they provide a flexible way to manage translations and other settings. Moreover, by using Custom Metadata Types, administrators can make adjustments directly through the user interface, ensuring a seamless experience. Consequently, this approach minimizes the need for frequent code deployments and enhances system adaptability.

    Steps to Create Custom Metadata Types:

    Navigate to Custom Metadata Types: Go to Setup. Search for Custom Metadata Types and click on it.
    Create a New Custom Metadata Type: Click on New Custom Metadata Type. Name it (e.g., TranslationSettings). Add fields like Label, Translation, and Language to store the relevant data.
    Add Records: Go to Custom Metadata Types and select Manage Records for your type. Click New to create records with translations for different languages.

    Developing the Lightning Web Component (LWC)

    The LWC will dynamically fetch and display translations based on the user’s language preferences.

    Sample Code:

    HTML (translationComponent.html):

    html

    <template>

        <lightningcard title={cardTitle}>

            <div class=”sldsparound_medium”>

                <p>{translatedText}</p>

            </div>

        </lightningcard>

    </template>

    JavaScript (translationComponent.js):

    javascript

    import { LightningElement, wire } from ‘lwc’;

    import getTranslations from ‘@salesforce/apex/TranslationController.getTranslations’;

    export default class TranslationComponent extends LightningElement {

        translatedText = ”;

        cardTitle = ‘Welcome Card’;

        @wire(getTranslations)

        handleTranslations({ error, data }) {

            if (data) {

                this.translatedText = data.Translation__c;

            } else if (error) {

                console.error(‘Error retrieving translations:’, error);

            }

        }

    }

     

    Apex Controller (TranslationController.cls):

    apex

    public with sharing class TranslationController {

        @AuraEnabled(cacheable=true)

        public static TranslationSettings__c getTranslations() {

            // Fetch the translation record based on user preferences

            return [SELECT Translation__c FROM TranslationSettings__c LIMIT 1];

        }

    }

    Testing and Output

    After deploying the component, the translations should display based on the user’s locale settings.

    Expected Output:

    For a user whose language preference is set to French, if the custom metadata record contains the French translation, the output will be:

    Bienvenue dans notre application !

     

    This text will replace the default English message in the component.

    Common Issues and Solutions

    Issue 1: Translation Not Displaying

    Problem: The translated text does not appear as expected.

    Solution: Ensure that custom metadata records are properly set up and associated with the correct language. Also, check if the Apex method is correctly fetching the data.

    Issue 2: Apex Method Errors

    Problem: Errors occur when the Apex method is called.

    Solution: Verify that the method is correctly annotated with @AuraEnabled and that it adheres to Salesforce governor limits. Ensure proper exception handling and debug the controller logic if needed.

    Issue 3: Incorrect Custom Label Values

    Problem: Custom label values are not displaying correctly.

    Solution: Check the custom labels setup in Salesforce. Ensure that the correct namespace is used in the JavaScript file when importing labels and that translations are properly configured.

    Conclusion

    Implementing translations in Salesforce using Custom Labels, Custom Metadata Types, and Lightning Web Components involves setting up the necessary Salesforce configurations, developing the component to dynamically handle translations, and troubleshooting common issues. By following these steps, you can create a multilingual user experience that enhances accessibility and user satisfaction across different locales.

    If you encounter any challenges, remember that Salesforce’s robust tools and community resources can assist you in resolving issues and optimizing your implementation. Happy coding!

    Check out for more :

    Custom Metadata Types in Salesforce

    Custom Label

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleUsing Tabulator in Lightning Web Components
    Next Article Email Automation with setTargetObjectId

    Related Posts

    Machine Learning

    Salesforce AI Releases BLIP3-o: A Fully Open-Source Unified Multimodal Model Built with CLIP Embeddings and Flow Matching for Image Understanding and Generation

    May 16, 2025
    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 16, 2025
    Leave A Reply Cancel Reply

    Hostinger

    Continue Reading

    From Edges to Nodes: SEGMN’s Comprehensive Approach to Graph Similarity

    Development

    I tested DJI’s new foldable drone, and would recommend it to both beginners and professionals

    News & Updates

    The Thunderbird email client finally landed on Android, and it was worth the wait

    Development

    Automate the deployment of Amazon RDS for Db2 Instances with Terraform

    Databases

    Highlights

    CVE-2025-44071 – SeaCMS Phomebak PHP Remote Code Execution Vulnerability

    May 5, 2025

    CVE ID : CVE-2025-44071

    Published : May 5, 2025, 10:15 p.m. | 1 hour, 19 minutes ago

    Description : SeaCMS v13.3 was discovered to contain a remote code execution (RCE) vulnerability via the component phomebak.php. This vulnerability allows attackers to execute arbitrary code via a crafted request.

    Severity: 0.0 | NA

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    This might be the end of ChromeOS, but what’s next could be better

    December 31, 2024

    Code Your Own Llama 4 LLM from Scratch

    April 24, 2025

    Catching a phish with many faces

    May 10, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.