<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: George Kasiouras</title>
    <description>The latest articles on DEV Community by George Kasiouras (@georgek).</description>
    <link>https://dev.to/georgek</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F902086%2F54969537-56a2-4fae-85b3-a1bc7ac4ef74.jpg</url>
      <title>DEV Community: George Kasiouras</title>
      <link>https://dev.to/georgek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/georgek"/>
    <language>en</language>
    <item>
      <title>How to Implement Angular Localization</title>
      <dc:creator>George Kasiouras</dc:creator>
      <pubDate>Wed, 16 Nov 2022 13:01:49 +0000</pubDate>
      <link>https://dev.to/georgek/how-to-implement-angular-localization-2bg5</link>
      <guid>https://dev.to/georgek/how-to-implement-angular-localization-2bg5</guid>
      <description>&lt;p&gt;Angular localization can be a challenging task, from internationalization to content extraction all the way back to deployment. This is what you'd typically do with Angular i18 and other alternatives, due to their limitations. &lt;/p&gt;

&lt;p&gt;But there is a way to bypass these limitations. If you are looking to nail the localization of your Angular application, we have got you covered with this step-by-step guide to easily localize your app with an Angular i18 alternative called Transifex Native. &lt;/p&gt;

&lt;h2&gt;
  
  
  Angular i18 Limitations
&lt;/h2&gt;

&lt;p&gt;If you've ever worked on localizing an Angular app, you most likely already know that the most popular way to localize your Angular app is through the built-in &lt;a href="https://angular.io/guide/i18n-overview"&gt;Angular i18 module&lt;/a&gt;. But this process has some limitations:&lt;/p&gt;

&lt;p&gt;The locale cannot be changed at once but all the languages must be compiled and generated individually&lt;br&gt;
Custom translation loaders are not easy to create&lt;br&gt;
It only supports XML files which are more difficult to maintain than some alternatives.&lt;/p&gt;

&lt;p&gt;There are some other libraries, &lt;a href="https://www.i18next.com/"&gt;i18next&lt;/a&gt; for instance, that can bypass these limitations, but all of these methods require you to extract strings and deploy them when they are translated—which demands more effort to execute different localization tasks like branching, content splitting, or releasing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.transifex.com/blog/2022/angular-localization-getting-started-with-transifex-native/"&gt;Angular localization&lt;/a&gt; can be simplified using a different approach—Transifex Native—where you can directly use your code without managing files. All translatable content is managed by the platform and comes with added functionality that you can control. To use Transifex Native for localizing your application, simply &lt;a href="https://www.transifex.com/"&gt;sign up&lt;/a&gt; to the platform and get started with your project.&lt;/p&gt;
&lt;h2&gt;
  
  
  3 Benefits Over Angular i18
&lt;/h2&gt;

&lt;p&gt;We have discussed the limitations of the file-based approach for your app localization earlier in the article. But before diving into our recommended alternative, here are 3 ways the Transifex Native can solve the existing drawbacks.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automate file management&lt;/strong&gt;: The biggest drawback is transferring files to and from the TMS to your platform. This process gets even more complex when the number of files increases and hinders scalability. An easy solution to manual file management is automation which can be achieved with Transifex Native.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Easier for developers&lt;/strong&gt;: Developers can focus more on the code than the localization process itself as TX Native integrates localization within the code. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Better results&lt;/strong&gt;: No manual errors or updating translations to your app. Native also optimizes the entire process by giving different team members the scope to completely focus on their roles without worrying about coordinating everything on their platform. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that you understand how Transifex Native can simplify your localization process, let’s take you through a step-by-step guide on how you can localize your Angular app.&lt;/p&gt;
&lt;h2&gt;
  
  
  How To Localize Angular Application?
&lt;/h2&gt;

&lt;p&gt;To localize your app using Transifex, simply add the Native SDK and you are ready to serve translations over the air.&lt;/p&gt;

&lt;p&gt;Once you have created your project, follow the next steps to install the Transifex SDK in your application and get started with your Angular localization:&lt;/p&gt;
&lt;h2&gt;
  
  
  Generate Native Credentials
&lt;/h2&gt;

&lt;p&gt;In all data exchanges between the Native and your application, the Native credentials --TOKEN and SECRET -- are used.&lt;/p&gt;

&lt;p&gt;API TOKEN – Reads (GET) content from Transifex Native to your application&lt;br&gt;
API SECRET – Sends (POST) content from your application to Transifex Native&lt;br&gt;
Click on “Generate Native Credentials” and choose the TX Native SDK as Angular. It’s essential to copy and save the SECRET key for the future, as it cannot be recovered.&lt;/p&gt;
&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;To get started, you need to install the JavaScript SDK and add the additional Angular Components library to your code. Install the library and its dependencies using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @transifex/native @transifex/angular --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Declaration &amp;amp; Initialization Of The TX Native
&lt;/h2&gt;

&lt;p&gt;It is necessary to initialize the TX Native library at two locations in the angular bootstrap process to use its objects globally:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NgModule Initialization- To access all the elements provided by the TX Native Angular SDK in our application, you need to add the Native module to the code as follows:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@NgModule({
 declarations: [
  AppComponent,
  LoginComponent,
  TermsComponent,
  HomeComponent,
  PrivacyComponent
 ],
 imports: [
  AppRoutingModule,
  BrowserModule,

  //TX Native module declaration
  TXNativeModule.forRoot(),
 ],
 providers: [,
 ],
 bootstrap: [AppComponent]
}]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Application Bootstrap- Insert the translation service provided by the SDK and initialize the library using the token generated by Transifex. The service is a singleton object that can be used in any part of the application—an advantage of initializing the native library globally.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To implement this, use the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component } from '@angular/core';
import { TranslationService } from '@transifex/angular';

@Component({
 selector: 'app-root',
 templateUrl: './app.component.html',
 styleUrls: ['.app.component.scss']
})
export class AppComponent {
 constructor(private translationService: TranslationService) {
  // TX Native library initialization
  translationService.init({
   token: '---- insert your TX Native token here -----',
  });
 }
 async ngOnInit()
  await this.translationService.getLanguages();
  await this.translationService.setCurrentLocale('el');
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Internationalize Your Code With TX Native
&lt;/h2&gt;

&lt;p&gt;Once the SDK is installed, it’s time to mark the content for translation. Transifex Native provides multiple components that can be used in your code for internationalizing your content.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. T Component&lt;/strong&gt;&lt;br&gt;
This is used to mark the strings for translation, as in the example given below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p&amp;gt;
  &amp;lt;label&amp;gt;
   &amp;lt;T str="Password" key="label.password"&amp;gt;&amp;lt;/T&amp;gt;
  &amp;lt;/label&amp;gt;
  &amp;lt;input type="password" name="password" /&amp;gt;
&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Safe render of the HTML result after translation is possible with the T component, using the parameter sanitize. Ensure that the str (Source String) property on the T component is always a valid ICU message format template. In the case it is nested within a tx-instance tag, the T component will use new instances to fetch translations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. UT Component&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A UT component has similar behavior to a T component, but when the inline property is true, it renders the source string as HTML inside a div tag or a span tag.&lt;/p&gt;

&lt;p&gt;Inline property can be described as:&lt;/p&gt;

&lt;p&gt;Prop  -- Type   --  Description&lt;br&gt;
inline - Boolean -  If should wrap the translation with span (true) of with a div (default, if false)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The @T Decorator&lt;/strong&gt;&lt;br&gt;
This component is used in variable declarations inside classes and components to have properties with the translation and use them in templates and code.&lt;/p&gt;

&lt;p&gt;Decorators can use an alternative instance instead of the main TX Native one by passing them an instance configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. The Translate Pipe&lt;/strong&gt;&lt;br&gt;
This can be used in templates for inline string translations. However, one limitation that the translate pipe has is that it cannot translate strings with embedded HTML.&lt;/p&gt;

&lt;p&gt;In the case it is nested within a &lt;strong&gt;tx-instance tag&lt;/strong&gt;, the translate pipe will use new instances to fetch translations.&lt;/p&gt;

&lt;p&gt;These components are used to execute the primary internationalization process like marking the strings for translation or passing attributes. If you want to get some variables translated in the component’s code, you can implement it as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@component({
 selector: 'app-root',
 templateUrl: './app.component.html',
 styleUrls: ['.app.component.css']
})
export class AppComponent {
 @T( 'Angular Transifex Native Demo')
 mainTitle!: string;
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then use the variable in the component’s template like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span&amp;gt;&amp;lt;UT str='{title} is running!" [vars]="{ title: mainTitle }"&amp;gt;&amp;lt;/UT&amp;gt;&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using The Translation Service
&lt;/h2&gt;

&lt;p&gt;To initialize the TX Native object, this is the main service exposed by the SDK. As the translation service is a singleton instance, the initialization will be shared across the entire application—inside your libraries, components, or the code.&lt;/p&gt;

&lt;p&gt;Additionally, it keeps a collection of TX Native instances that can be added to the default instance for particular purposes.&lt;br&gt;
Each additional instance should have the following configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ITXInstanceConfiguration {
 token: string;
 alias: string;
 controlled: boolean;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add and retrieve the additional instances, exposed methods addInstance and getInstance are used, respectively. &lt;/p&gt;

&lt;p&gt;You can utilize the translation service to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Add or delete an alternative instance&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initialization of an instance&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set or get the current locale&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Translation of a string&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The translation service also allows retrieving translations that match a given list of tags—to fetch groups of translations in batches—for lazy loading and performance. To do this, you can use the &lt;strong&gt;fetchTranslations&lt;/strong&gt; method.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Language Picker Component
&lt;/h2&gt;

&lt;p&gt;For easy localization, the Angular SDK includes a ready-to-use component called a language picker. This component switches the application’s selected language when the current locale is changed. The language picker uses the Translation Service internally.&lt;/p&gt;

&lt;p&gt;The component accepts this property:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;className&lt;/strong&gt;: The CSS class that is applied to the  tag&lt;br&gt;
And it returns this property:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;localeChanged&lt;/strong&gt;: Handles the change of locale&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using the language picker component looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;tx-language-picker
 className="placeBottomLeft"
 (localeChanged)="onLocaleChanged($event)"&amp;gt;&amp;lt;/tx-language-picker&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You always can implement a language picker of your choice using the Translation Service and different methods provided by the Native.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pushing Source Content For Localization
&lt;/h2&gt;

&lt;p&gt;After you have marked the strings in the code for translation, you can push them to TX Native. To do so, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use a CLI tool that scans the code and extracts strings wrapped using the Native SDK. It scans all files in the selected folder and pushes the marked content to your Native project&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the SDK itself programmatically to push arbitrary strings coming from different sources like databases or custom files.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Find all the details to push your source strings to Transifex in this &lt;a href="https://developers.transifex.com/docs/javascript-sdk-uploading-source-content-to-transifex"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preview Translations
&lt;/h2&gt;

&lt;p&gt;Transifex Native automatically displays translated content in your application—simply add a language picker in your code. Transifex comes with an in-built language picker to request translations, but you can build your own picker using Native JS API and add the related logic.&lt;/p&gt;

&lt;p&gt;The translations are fetched from the CDS to the cache and made available when a new language is selected. &lt;/p&gt;

&lt;p&gt;To help you understand, here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tx.setCurrentLocale('el)
 .then(() =&amp;gt; console.log('content loaded'))
 .catch(console.log);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Fetching Translations
&lt;/h2&gt;

&lt;p&gt;Once you have pushed the translatable content, you can view or edit it in the Transifex editor. There is also a list of tools to assist you in your localization processes.&lt;/p&gt;

&lt;p&gt;Every time you save a translation, it automatically becomes available over the air in your application. Transifex Native translations are served from a secure CDN server, called Transifex CDS, and are updated once per hour. You do not need to restart your server or deploy any code to see the newest translations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Optimizing The App Localization Process
&lt;/h2&gt;

&lt;p&gt;Apart from simplifying the localization process as a whole, Transifex Native is loaded with a wide range of tools that can optimize your workflow further.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using String Keys
&lt;/h2&gt;

&lt;p&gt;Keys are unique identifiers that can be reused in other parts of the code to minimize the amount of content your localization team has to translate. Multiple strings with the same key are pushed as a single string in TX Native—which means your team now needs to add only a single translation.&lt;/p&gt;

&lt;p&gt;Keys can be used by adding the _key parameter to the T component and marking strings as translatable in the Native function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Content Splitting
&lt;/h2&gt;

&lt;p&gt;Segment your string content using tags and optimize the bundle size of downloaded translations over the air. This is useful when you have a large content resource but not all parts of your app need the whole content. To segment your content, simply use any preexisting tags or create a new one.&lt;/p&gt;

&lt;p&gt;This can also be used to segment content across feature branches—tag the strings, localize them, test them, and deploy them.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git checkout -b new-login-page
$ txjs-cli push srv/ --append-tags="new-login-page"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Automated Releasing
&lt;/h2&gt;

&lt;p&gt;When your feature or branch is ready for deployment, clean up all the faulty content from the Native CLI tool using the purge attribute when pushing. This makes the entire process automated and you don’t end up with multiple string history.&lt;/p&gt;

&lt;p&gt;Purge will parse all code files found in the  and keep only those phrases detected there, removing any other phrases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Solutions such as Angular i18 require your team to go back and forth with content to be localized. Transifex Native bypasses the need for manual file management and provides a simpler way to localize your app.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The Ultimate Guide to JavaScript Localization</title>
      <dc:creator>George Kasiouras</dc:creator>
      <pubDate>Tue, 23 Aug 2022 15:02:00 +0000</pubDate>
      <link>https://dev.to/georgek/the-ultimate-guide-to-javascript-localization-38pf</link>
      <guid>https://dev.to/georgek/the-ultimate-guide-to-javascript-localization-38pf</guid>
      <description>&lt;p&gt;JavaScript is the world’s most popular programming language according to a &lt;a href="https://insights.stackoverflow.com/survey/2020#technology-programming-scripting-and-markup-languages-professional-developers" rel="noopener noreferrer"&gt;survey&lt;/a&gt; conducted by Stackoverflow, having a staggering 69.7% popularity score as compared to other programming languages. &lt;/p&gt;

&lt;p&gt;Its usefulness in both being the language of the browser and also its backend role in &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; makes it the ideal developer stack.&lt;/p&gt;

&lt;p&gt;The influence of JavaScript is also magnified by its use in many multiplatform mobile frameworks, game engines, and even in the world of cloud computing, therefore the demand for JavaScript localization comes as no surprise.&lt;/p&gt;

&lt;p&gt;In this article, we are going to be taking a look at JavaScript localization and how to go about it in a 2-way approach. Firstly, with a file-based translation which uses Transifex to get translations and use them in our applications locally, and secondly, with the use of Transifex Native, which is a cloud-based localization stack whose SDK can be installed or used via a CDN with no need for files.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Localization?
&lt;/h2&gt;

&lt;p&gt;Localization involves the process of converting content to suit specific locations, i.e., multiple languages during the internationalization of your project. It simply means to design software in a way that can handle multiple locations, languages, and regions. &lt;/p&gt;

&lt;p&gt;Localization also doesn’t just dwell on languages, it can also be used to address some other forms of media which include images, voice notes, and embedded sounds locals would be very familiar with in their specific regions.&lt;/p&gt;

&lt;p&gt;There are a lot of possibilities out there on how to achieve localization with JavaScript but most developers are uncertain on how to go about it, whether it's selecting the right tools, frameworks, or libraries; there’s a whole lot of research and brainstorming that needs to be done to make the process smoother.&lt;/p&gt;

&lt;p&gt;This step-by-step guide aims to teach you all that you need to know to localize a JavaScript website, app, or software with Transifex, a platform that’s ideal for the task of localization and internationalization for any level of developer. &lt;/p&gt;

&lt;h2&gt;
  
  
  Ways to Localize a JavaScript Project
&lt;/h2&gt;

&lt;p&gt;There are two ways to localize your javaScript project which are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;File-based: Meaning that your content needs to be extracted in the form of a file and uploaded to the Translation Management System (TMS), then you would typically translate the content, download it back from the TMS and upload it back to your app/website and deploy the changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fileless: This process involves installing a plugin directly to your code and having the TMS sync your translations without having to go through the above-mentioned process&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The File-Based Approach to JavaScript Localization
&lt;/h2&gt;

&lt;p&gt;Internationalization as earlier defined is the process of designing and building software so it can be adaptable to different users from different cultures, regions, and languages. It also entails adapting software to accept several forms of data and settings to match local customs to be processed correctly.&lt;/p&gt;

&lt;p&gt;In the process of designing software to suit several languages as described above, your approach might be to have code locally localized without the use of libraries, a CDN, or several configuration exercises. This local process is highly feasible as it involves creating local files which have been translated by several individuals into different languages.&lt;/p&gt;

&lt;p&gt;Alright, let’s say we have a page we want to localize as shown below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="c"&gt;&amp;lt;!-- ./index.HTML --&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;JavaScript Transifex Demo&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;nav&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"navbar"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"logo"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Local JS&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"navbar-right"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="nt"&gt;&amp;lt;select&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"localization-switcher"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"locale-switcher"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;English&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"fr"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;French&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"ar"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Arabic (العربية)&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                        &lt;span class="nt"&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"content-section"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;localization-key=&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                    Welcome to this localization demo site
                &lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;localization-key=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                    Software localization is the process of adapting software to the culture and language of an end user, from standards of measurement to video and graphic design. It involves translation, design, and UX changes to make software look and feel natural to the target user.
                &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./js/script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The current content in the code is hardcoded, and for the purpose of file-based localization, all the content is extracted into a file, most likely in a JSON format, and then retrieved from a file.&lt;br&gt;
The next step is to make a file in a language folder within your code to keep track of all files for different languages:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;


&lt;/span&gt;&lt;span class="err"&gt;&amp;lt;!--&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;./lang/en.json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;--&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;

    &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Welcome to this localization demo site"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;

    &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Software localization is the process of adapting software to the culture and language of an end user, from standards of measurement to video and graphic design. It involves not only translation but also design and UX changes to make software look and feel natural to the target user."&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;



&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;A fetch request can then be used to replace the static content in the HTML file with the content from the JSON below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;


&lt;span class="c"&gt;&amp;lt;!--&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt; &lt;span class="o"&gt;--&amp;gt;&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;translations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`lang/en.json`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="p"&gt;})&lt;/span&gt;

        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

            &lt;span class="nx"&gt;translations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

            &lt;span class="nf"&gt;translatePage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nf"&gt;fetchContent&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;translatePage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[localization-key]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;localization-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;translation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;translations&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

        &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;translation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="p"&gt;};&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We’ve successfully retrieved the entire content from the JSON file in the above code snippet. Here the querySelectorAll() method was used to find all elements with the “localization-key” property that we assigned in our HTML file, looped through to see the attribute that matched the key of our object, and finally embedded the data.&lt;/p&gt;

&lt;p&gt;So far so good, we’ve seen how to read data from a file using vanilla JavaScript, however, for file-based localization, Transifex allows the upload of a source file which is the English version of our content for this demo (&lt;code&gt;en.json&lt;/code&gt;). After this initial stage, a platform can then be used to translate the content, after which it can be downloaded and the localized content fetched.&lt;/p&gt;

&lt;p&gt;We’ll look at how to create a file-based project on Transifex and then upload our source content for translation. Transifex would take care of the translation and we can then download the translated content.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Create a File-Based Project on Transifex
&lt;/h2&gt;

&lt;p&gt;The first point of entry into the Transifex universe is by creating an account. You can Sign Up with your GitHub, Google, or LinkedIn account, which is free for 15 days, and free forever for open-source projects.&lt;/p&gt;

&lt;p&gt;After account creation, you need to create a project. A name must be given to the project and “File-based” should be selected as your project type.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1tqwatscxsd59zz30ii1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1tqwatscxsd59zz30ii1.png" alt="JavaScript Localization - File-based - Transifex"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, you must specify your application’s primary language and the language(s) into which we will translate it. We’ll use English as the primary language for this guide, with French and Arabic as our target languages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Uncheck the box that asks if you want to add a demo file automatically unless you want to use it to test the Transifex platform first.&lt;/p&gt;

&lt;p&gt;When you finish, click on the “Create Project” button.&lt;br&gt;
Following that, we will direct you to the next page, where you can upload your source file in any supported format. but we will use the JSON format.&lt;/p&gt;

&lt;p&gt;After creating your project, select the “Upload file” button to upload your extracted JSON file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F66o02jr1x0dhlibjx8q3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F66o02jr1x0dhlibjx8q3.png" alt="JavaScript Localization - File-based"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When that is done, you’re all set to start translating your content into the editor!&lt;/p&gt;

&lt;h2&gt;
  
  
  Downloading Your Translated Content From Transifex
&lt;/h2&gt;

&lt;p&gt;After the above process has been finalized, we can go ahead with downloading the translated file after successful translation into the content of our application. &lt;/p&gt;

&lt;p&gt;To download the translated file, navigate to your project’s language tab, click on the file, and then select “&lt;strong&gt;Download only reviewed translations&lt;/strong&gt;”. Transifex will allow us to download a JSON file of your translated language:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd5ir8n87g8uyp65c9kqm.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd5ir8n87g8uyp65c9kqm.gif" alt="JavaScript localization guide"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Please ensure to save the file with the locale name in the &lt;code&gt;lang&lt;/code&gt; folder we created earlier, e.g., &lt;code&gt;./lang/ar.json&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Loading Translations Asynchronously From Local Files
&lt;/h2&gt;

&lt;p&gt;We’re off to a good start by translating our source file (&lt;code&gt;en.json&lt;/code&gt;) into Arabic (&lt;code&gt;ar.json&lt;/code&gt;), and we have saved both in the languages (&lt;code&gt;lang&lt;/code&gt;) folder. We were also able to load data from the source file previously. Now, let’s implement loading our translations asynchronously: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;


&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;locale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;translations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DOMContentLoaded&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nf"&gt;setLocale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setLocale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newLocale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nx"&gt;translations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetchTranslations&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newLocale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;translatePage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchTranslations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newLocale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`lang/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;newLocale&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.json`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;translatePage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[localization-key]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;localization-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;translation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;translations&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

        &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;translation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="p"&gt;};&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The code above is very similar to the code we used to retrieve data from the source file. We’re doing it asynchronously, so it loads content based on the &lt;code&gt;**locale**&lt;/code&gt; parameter. Let’s go over the code again.&lt;/p&gt;

&lt;p&gt;First, we declared two variables to specify the locale we want to retrieve based on the available locales. As we can see, we set ours to &lt;code&gt;**ar**&lt;/code&gt;, which is the language code for Arabic:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;locale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;translations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We then created an &lt;code&gt;**addEventListener()**&lt;/code&gt; that gets triggered when the page content is readily using the &lt;code&gt;**DOMContentLoaded**&lt;/code&gt; event. In this &lt;code&gt;**addEventListener()**&lt;/code&gt; we called the &lt;code&gt;**setLocale()**&lt;/code&gt; function and passed the &lt;code&gt;**locale**&lt;/code&gt; variable.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DOMContentLoaded&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setLocale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The core function is &lt;code&gt;setLocale()&lt;/code&gt;, and it performs two major tasks: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Loading translations for the given locale &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Translating the page to show specified language localized content:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setLocale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newLocale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;translations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetchTranslations&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newLocale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;translatePage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As seen in the &lt;code&gt;**setLocale()**&lt;/code&gt; function, we first fetched our translations, and as we can see, we used async/await to get the translations before triggering the function that will load our page with the fetched content. We passed the locale to the &lt;code&gt;**fetchTranslations()**&lt;/code&gt; function and used it to retrieve content from the locale file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchTranslations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newLocale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`lang/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;newLocale&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.json`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Finally, when we have gotten the content, we now pass this content to our page, so it appears using the second function in the setLocale function, which is &lt;code&gt;**translatePage()**&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;translatePage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[localization-key]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;localization-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;translation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;translations&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;translation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  The Fileless-Based Approach to JavaScript Localization
&lt;/h2&gt;

&lt;p&gt;The fileless-based approach to &lt;a href="https://www.transifex.com/blog/2022/javascript-localization/" rel="noopener noreferrer"&gt;JavaScript Localization&lt;/a&gt; is what we can describe as “&lt;strong&gt;Transifex Native&lt;/strong&gt;”. &lt;/p&gt;

&lt;p&gt;This approach enables you to allow the localization platform directly communicate with your codebase and allow pull/push content automatically. This approach is a better alternative to the traditional approach involved in the file-based approach to localization. Here’s how to get started with a fileless-based approach:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a Transifex account if you don’t have one already.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a Transifex Native project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Specify your application’s primary language and the language(s) into which we’ll translate it.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For this guide, English would be the primary language while French and Arabic are going to be the target languages. When finished with all of the above, click on the Create Project button, after which you will be directed to the next page where you’ll find instructions for creating credentials for your project.&lt;/p&gt;

&lt;p&gt;At the bottom of the page, click on “&lt;strong&gt;Generate Native Credentials Now&lt;/strong&gt;”. The &lt;strong&gt;API &lt;em&gt;token&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;_secret_key&lt;/strong&gt; would be displayed in a pop-up window. Go ahead and copy both keys and safeguard them because they’re going to be very useful later. Clicking on the button would also show us the configurations we’ll use in our JavaScript file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl5w34lwqy8vug9dch98j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl5w34lwqy8vug9dch98j.png" alt="JavaScript Localization - Fileless - Transifex Native"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once all that is sorted, we can now proceed to push the content to Transifex and then localize it.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to Configure Transifex Native in Our JavaScript Project
&lt;/h2&gt;

&lt;p&gt;The first step into using Transifex native is configuring it. This can be done in numerous ways as seen in the &lt;a href="https://developers.transifex.com/docs/javascript-sdk-setup" rel="noopener noreferrer"&gt;Transifex JavaScript Documentation&lt;/a&gt;. However, for this particular guide, we’ll make use of the CDN and later make use of the Transifex CLI when we want to push our content.&lt;/p&gt;

&lt;p&gt;Now, let’s add the CDN to our HTML file and then we’ll be able to use Transifex directly in our JavaScript file.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;JavaScript Transifex Demo&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
   // ...
       &lt;span class="nt"&gt;&amp;lt;script
            &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/javascript"&lt;/span&gt;
&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.jsdelivr.net/npm/@transifex/native/dist/browser.native.min.js"&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./index.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Once this is done, we can then head over to our JavaScript file to configure Transifex using the token we got earlier when creating our project.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Transifex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Transifex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ADD TOKEN KEY HERE.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  How to Push Content to Transifex with JavaScript
&lt;/h2&gt;

&lt;p&gt;We’ve successfully configured Transifex locally in our JavaScript file after following the above steps. Now, we want to push our content directly with the Transifex CLI without the use of any external files as seen in the file-based approach.&lt;/p&gt;

&lt;p&gt;To achieve this, we have to first create a package.json file and then install the Transifex CLI dependency by running the following commands:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;


&lt;span class="nv"&gt;$ &lt;/span&gt;npm init &lt;span class="nt"&gt;-y&lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @transifex/cli &lt;span class="nt"&gt;--save&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Once this is done we will see that Transifex CLI has been installed in our package.json file dependency object:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"@transifex/cli"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^4.2.2"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can now proceed to push our content with the &lt;code&gt;t&lt;/code&gt; function. As we can see below, we also used the &lt;code&gt;_key&lt;/code&gt; parameter to give each content a key, so it’s easy to fetch that content later:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Transifex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Transifex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ADD TOKEN KEY HERE&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="nf"&gt;t&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Welcome to this localization demo site&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;_key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="nf"&gt;t&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Software localization is the process of adapting software to both the culture and language of an end user, from standards of measurement to video and graphic design. It involves not only translation, but also design and UX changes to make software look and feel natural to the target user.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;_key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;description&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So far, we have initialized the content we want to push to Transifex for localization. Let’s now push the content with the &lt;code&gt;@transifex/cli&lt;/code&gt; library, which will collect all translatable strings and push them to Transifex using the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

$ ./node_modules/.bin/txjs-cli push src/ --token=&amp;lt;PROJECT TOKEN&amp;gt; --secret=&amp;lt;PROJECT SECRET&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: In the command above, ensure you add your token and secret key. You will also notice that we use &lt;code&gt;src/&lt;/code&gt;, which means this command will look for the &lt;code&gt;index.js&lt;/code&gt; file in the &lt;code&gt;src&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;index.js&lt;/code&gt; file is the file that contains the content we want to push. Ensure you place your HTML, CSS, and JavaScript file in an &lt;code&gt;src&lt;/code&gt; folder as seen in this &lt;a href="https://github.com/olawanlejoel/JS-localization-transifex/tree/main/Transifex%20Native" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Pull Localized Content From Transifex
&lt;/h2&gt;

&lt;p&gt;Retrieving content from Transifex is similar to how we first retrieved data from JSON files. Here, the only significant difference is that there is no need for the use of the fetch API for data retrieval.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;locale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DOMContentLoaded&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setLocale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setLocale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newLocale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setCurrentLocale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newLocale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;translatePage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;translatePage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[localization-key]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;localization-key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;translation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;t&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;translation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the code above, we specified the locale from which we wanted to retrieve its localized content. We created a function to retrieve the data, which is the &lt;code&gt;**setLocale()**&lt;/code&gt; method, and finally, we used the &lt;code&gt;**translatePage()**&lt;/code&gt; method to help get each content based on the &lt;code&gt;key&lt;/code&gt; and pass it to the UI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this step by step guide, we learned the two major methods for implementing JavaScript localization, namely, File-based and Fileless.&lt;/p&gt;

&lt;p&gt;Both methods work effectively. But for large projects, the file-based approach becomes extremely difficult to manage.&lt;/p&gt;

&lt;p&gt;This scalability deficit brings to light the efficiency of Transifex native in localization as translations are not included in your codebase as shown in this guide. &lt;/p&gt;

&lt;p&gt;Need more info on how fileless JavaScript localization works? Feel free to check out &lt;a href="https://docs.transifex.com/javascript-sdk/" rel="noopener noreferrer"&gt;Transifex Native's documentation&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>l10n</category>
      <category>tutorial</category>
      <category>guide</category>
    </item>
    <item>
      <title>Android Localization: A Step-by-Step Guide to Localize your App</title>
      <dc:creator>George Kasiouras</dc:creator>
      <pubDate>Tue, 02 Aug 2022 14:15:07 +0000</pubDate>
      <link>https://dev.to/georgek/android-localization-a-step-by-step-guide-to-localize-your-app-3bal</link>
      <guid>https://dev.to/georgek/android-localization-a-step-by-step-guide-to-localize-your-app-3bal</guid>
      <description>&lt;p&gt;Did you know that Android holds 72.11% of the global &lt;a href="https://gs.statcounter.com/os-market-share/mobile/worldwide"&gt;market share&lt;/a&gt; making it the leading operating system worldwide?&lt;/p&gt;

&lt;p&gt;With so many people using Android devices, your app must be relevant to them if you want to go global. The best way to do this is through Android localization of your app—the majority of the world doesn't speak English, so users prefer applications that display text, numbers, currency, etc. according to their region.&lt;/p&gt;

&lt;p&gt;A lot of developer tools are available in Android Studio to implement app localization. But this can turn complex as you need to rack up in-house resources and teams capable of building and managing localization from scratch. &lt;/p&gt;

&lt;p&gt;This tutorial shows you how to localize your Android app by using Transifex.&lt;/p&gt;

&lt;p&gt;Transifex is a localization management tool that you can use to upload, manage, and translate all of your content. And you can do that with one of two ways: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;File-based&lt;/li&gt;
&lt;li&gt;Fileless with automatic push &amp;amp; pull requests&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is how to do it with both methods!&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Android Localization?
&lt;/h2&gt;

&lt;p&gt;Localization (l10n) is how your product or app translates and adapts itself to the specific needs of a locale. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.transifex.com/blog/2021/android-localization-an-advanced-guide-for-transifex-native/"&gt;Android localization&lt;/a&gt; deals with this process by adjusting various elements of your app including text strings, numbers, audio files, and image formats, to suit the user experience.&lt;/p&gt;

&lt;p&gt;But before you step into localization, it is important to internationalize (il8n) your application elements. Ensure that your text resources are not hardcoded to remove any language dependencies, enabling smooth localization for different target audiences.&lt;/p&gt;

&lt;h2&gt;
  
  
  Android Localization: Getting Started
&lt;/h2&gt;

&lt;p&gt;The first step is to create a Transifex account—sign up, which is free for 15 days, or free forever if you are using the open-source version. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;After the account creation, you will be asked to create a project. Alternatively, you can also explore their demo project to get an overview of how the platform works. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On the next page, choose your project name and type. You can either opt for ‘File Based’ or ‘Native’ as your project type. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose the main language of your application and the target language that you will be translating the content to. Here, we are choosing English and French as references. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once you are done, click on ‘Create Project’&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7yjknZHu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7z48j7pe48aimyiquvxo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7yjknZHu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7z48j7pe48aimyiquvxo.png" alt="Image description" width="880" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  File-Based Android Localization
&lt;/h2&gt;

&lt;p&gt;This app localization method includes a pretty straight-forward approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You upload the source files to Transifex.&lt;/li&gt;
&lt;li&gt;The files are translated according to the target language file.&lt;/li&gt;
&lt;li&gt;The translated files are downloaded and moved back to the project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Android uses an XML-based file format for localization with three types of entries: strings, string-array, and plurals.&lt;/p&gt;

&lt;h2&gt;
  
  
  Upload A Source File
&lt;/h2&gt;

&lt;p&gt;Once you are inside your project dashboard, select the project you want to create a translation for.&lt;/p&gt;

&lt;p&gt;In case there aren’t any existing resources, drag and drop your file or click on ‘Upload a File’.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iFzqk-IG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zbknidhnw8xfb9gqm1oi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iFzqk-IG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zbknidhnw8xfb9gqm1oi.png" alt="Image description" width="880" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select your file, edit the resource name, and choose the file format. Once done, hit on ‘Upload File’.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TOEILMZ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qm0b6vrybwkmxqaokz9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TOEILMZ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qm0b6vrybwkmxqaokz9.png" alt="Image description" width="880" height="367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If your project already has resources, click on ‘Resources’ from the navigation menu. On the next page, select ‘Add Resources’ to upload the source file. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kRlBHOAz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yoijey8zgdyox6c8v92b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kRlBHOAz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yoijey8zgdyox6c8v92b.png" alt="Image description" width="880" height="375"&gt;&lt;/a&gt;      &lt;/p&gt;

&lt;p&gt;Drag and drop your file or click on ‘Select Resources’ to import it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3E-wBiPN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f874jidjxszp9m94a3v3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3E-wBiPN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f874jidjxszp9m94a3v3.png" alt="Image description" width="880" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Change the name of the resource and choose the file format. Once done, click on ‘Upload File’.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VVHAfzGA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1yt3a860aauc8c4p0v2y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VVHAfzGA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1yt3a860aauc8c4p0v2y.png" alt="Image description" width="880" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Upload A Translation File
&lt;/h2&gt;

&lt;p&gt;If you already have translations done outside of Transifex, you can import them into the platform. In this case, any existing translations will be overwritten with the ones from the uploaded file. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;From the project dashboard, click on the project you want to add the translations to.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on ‘Resources’&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the source file you would like to add translations for&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the target translation language&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When the popup appears, click on ‘Upload File’ or ‘Upload XLIFF file’. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--akLq5fAr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uqjyg3krks8molkmxgqx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--akLq5fAr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uqjyg3krks8molkmxgqx.png" alt="Image description" width="880" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use Upload File when the translation file is of the same format as the source file. If your translation file is downloaded earlier from Transifex as an XLIFF and you want to upload it again, use Upload XLIFF File.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use The Editor
&lt;/h2&gt;

&lt;p&gt;Translators can use Transifex's inbuilt editor to work on content without having to worry about handling files. It can be accessed from any web browser, and multiple people can translate the same document simultaneously. &lt;/p&gt;

&lt;p&gt;After you have uploaded your source file, select it and click on ‘Translate’. On the next page, you can view the source strings on the left and an editor for translation.&lt;/p&gt;

&lt;p&gt;The strings can be edited manually or via machine translation (Google Translate, Microsoft Translator, Amazon Translate, DeepL Translate, or KantanMT). Machine translation is not generally recommended but can be helpful in certain cases, for example, if you are dealing with a lot of non-customer-facing content. &lt;/p&gt;

&lt;p&gt;Use the editor to enter the translations for the specific strings and click on "Save Translation." Once done, review it to make any additional changes and save it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FY0-O5zs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxj8y7ra8a5thaqwo9ad.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FY0-O5zs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxj8y7ra8a5thaqwo9ad.png" alt="Image description" width="880" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Download the Translated File
&lt;/h2&gt;

&lt;p&gt;After the translations are done, it’s time to download the file. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;From the project navigation menu, choose the project you are working on. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select ‘Resources’ link and click on the resource that has been translated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the target language for translation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the popup, click on ‘Download for use". It gives you only translated strings in the file. In case you want only reviewed strings, hit 'Download only reviewed translations'. .Use 'Downloaded file to translate’ if you want to get untranslated source strings show a blank translation field. To translate outside Transifex, select ‘Download for translation as XLIFF’.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V_pKj5wV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/60nclchqww6fcbhn3dy5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V_pKj5wV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/60nclchqww6fcbhn3dy5.png" alt="Image description" width="880" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While this is a great approach for developers looking to handle the entire situation manually, complexity may rise when new strings are added or translations have to be updated. Also, having multiple developers handle translations manually doesn’t seem to be the best way to manage large-scale data.&lt;/p&gt;

&lt;p&gt;If you are someone who doesn’t like the idea of manual processes, you can easily implement Android localization in your app by integrating Transifex Native.&lt;/p&gt;

&lt;h2&gt;
  
  
  Android Localization: The Fileless Solution
&lt;/h2&gt;

&lt;p&gt;If you don't want to bother with the whole process of the file-based method, Android Localization with Transifex Native only requires you to install the provided SDK to your app and you are ready to push or pull content for localization directly with Transifex, with no need for files.&lt;/p&gt;

&lt;p&gt;With Native SDK, localization is done parallelly when any new code is released to your application. &lt;/p&gt;

&lt;p&gt;Use these steps to install the Transifex SDK in your application and get started with your Android localization:&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Transifex Native Project
&lt;/h2&gt;

&lt;p&gt;To get started, you will need to head to &lt;a href="https://www.transifex.com/"&gt;Transifex &lt;/a&gt; create an account, if you don't have one already, and create a native project. Then select ‘Create a new project’ and choose the type as Transifex Native. &lt;/p&gt;

&lt;p&gt;On the next page, you will find the dashboard where you are asked to share certain instructions with your developer team. You will also find ‘Generate Native Credentials Now’ at the bottom of the screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8p_t84vA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11bynq1ble23jnmh0akj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8p_t84vA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11bynq1ble23jnmh0akj.png" alt="Image description" width="880" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Generating Native Credentials
&lt;/h2&gt;

&lt;p&gt;The Native credentials—TOKEN and SECRET are used in all the data exchanges between the Transifex Native and your application. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;API TOKEN – It reads (GET) content from Transifex Native into your app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;API SECRET – It sends (POST) content from your application to Transifex Native for localization.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Generate the credentials and keep a copy for all future cases. Once created, you can manage them from the resources link.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Android SDK
&lt;/h2&gt;

&lt;p&gt;The Android Native SDK requires 18 (Android 4.3) or higher and uses appcompat 1.2.0.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Include the SDK as a package dependency, &lt;strong&gt;implementation **&lt;/strong&gt;'com.transifex.txnative:txsdk:0.x.y'** and replace &lt;strong&gt;‘x’&lt;/strong&gt; and &lt;strong&gt;‘y’&lt;/strong&gt; with the latest version numbers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Configure the SDK in your Application class and replace the &lt;strong&gt;&lt;/strong&gt; with the one provided in your Transifex Native project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You will need to replace &lt;strong&gt;&lt;/strong&gt; in your code with the languages you want your app to display. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s a configuration example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WSQ2BAcl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/evghhzl6i9qv5z4ayjra.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WSQ2BAcl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/evghhzl6i9qv5z4ayjra.png" alt="Image description" width="880" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Internationalize Your Code
&lt;/h2&gt;

&lt;p&gt;On top of the existing string resource-related methods, like &lt;strong&gt;getString()&lt;/strong&gt; and &lt;strong&gt;getText()&lt;/strong&gt;, the SDK offers Transifex Native's OTA translation capabilities.&lt;/p&gt;

&lt;p&gt;To use the SDK in multiple areas of your code, refer to this documentation here. &lt;/p&gt;

&lt;h2&gt;
  
  
  Push Source Content To The Content Delivery Service
&lt;/h2&gt;

&lt;p&gt;Use the &lt;a href="https://github.com/transifex/transifex-java/tree/devel/TransifexNativeSDK/clitool"&gt;CLI tool&lt;/a&gt; for exporting the strings from your app to Transifex for localization. &lt;/p&gt;

&lt;p&gt;To run the CLI tool, replace &lt;strong&gt;/path/to/&lt;/strong&gt; with the folder you added the tool in, as seen below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4dbHeZ32--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lplk5qz58f7v6o4vfupz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4dbHeZ32--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lplk5qz58f7v6o4vfupz.png" alt="Image description" width="880" height="48"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Replace &lt;strong&gt;app_module_name&lt;/strong&gt; with the name of your module that refers to the strings.xml file containing your source content.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the push command of the command-line tool to provide the transifex_token and transifex_secret that you created in your project.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QwQAm-sj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zh4zcyu8tg4eulou9vh4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QwQAm-sj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zh4zcyu8tg4eulou9vh4.png" alt="Image description" width="880" height="48"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pull The Localized Content
&lt;/h2&gt;

&lt;p&gt;You can export the translated content to your code with the pull command from the command-line tool. &lt;/p&gt;

&lt;p&gt;Replace the &lt;strong&gt;&lt;/strong&gt; with your app module’s name, &lt;strong&gt;&lt;/strong&gt; with your Native Project token, and &lt;strong&gt;&lt;/strong&gt; with the target languages for translations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y159BPGR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/am6g8xz755g7qf4kwq0l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y159BPGR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/am6g8xz755g7qf4kwq0l.png" alt="Image description" width="880" height="48"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If there are no cached translations found, by default, the Android Native SDK uses the existing strings.xml file and translations already cached in the app.&lt;/p&gt;

&lt;p&gt;Use the command fetchTranslations() to get the latest translations for all locales in your app. These will be available the next time your app runs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Native performs CDS cache invalidation automatically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Whether you choose the file-based format or Transifex Native to work with, following these steps will let you easily perform translations for your Android app.&lt;/p&gt;

&lt;p&gt;While the file-based format is a more manual approach for your localization where teams are in charge of all exports and imports of content to and from your project code, Transifex Native provides a simpler way to integrate the platform with your application.&lt;/p&gt;

&lt;p&gt;The simple UI and dashboard ensure your teammates are collaborating perfectly at all steps even if they are non-developers. &lt;/p&gt;

&lt;p&gt;So invite your team or even crowdsource your translations if you are an open-source project looking to engage with your community. &lt;/p&gt;

</description>
      <category>android</category>
      <category>l10n</category>
      <category>tutorial</category>
      <category>localization</category>
    </item>
  </channel>
</rss>
