Xamarin: How to use Localize to translate your Xamarin mobile application

This guide will walk you through the process of using Localize to translate your mobile application using the Xamarin framework.

What you'll learn

  • How to import files, translate files, export files, for use in your Xamarin mobile apps using one of the following file formats:
    • RESX files for Xamarin.Forms
    • Localizable.strings files for the Xamarin.iOS native platform
    • Android Strings files for the Xamarin.Android native platform

Prerequisites

  • You have a project set up in Localize
  • You have experience developing Xamarin mobile applications

Xamarin.Forms

Preparing your Xamarin.Forms for localization

When localizing the text content in your Xamarin.Forms you will be using RESX files. You will create a separate RESX file for each language. You should name the files using the same root name as the main resource file, adding the appropriate language code to the filename. For example:

  • Resources.resx - for the source language file
  • Resources.es.resx - for the Spanish target language file
  • Resources.fr.resx - for the French target language file

If you have hard-coded any copy into Xamarin.Forms directly you will need to apply best practices and abstract your strings into a RESX file.

When a user’s mobile device is changed to a different language, your mobile application will attempt to load resources for that language by loading the appropriate assembly. For example, if the mobile device is set to French your application will attempt to load resources from the assembly that contains the Resources.fr.resx file.

Using the Localize Dashboard to translate your Xamarin.Forms

Import your RESX file into Localize

  1. Within your Localize Dashboard go to the Phrases > File Import/Export page
  2. Select Import from the left submenu
  3. Select RESX as your file type
  4. Select the language you are importing
  5. Select an import type of Phrases
  6. Upload and submit your RESX file

Translate your imported phrases

Using the Localize dashboard, you may translate your source language phrases into as many languages as you need. If you are unfamiliar with the translation workflow, please see our Basic Translation Workflow with Localize video.

Export your translations into new RESX files

  1. Within your Localize Dashboard go to the Phrases > File Import/Export page
  2. Select Export from the left submenu
  3. Select RESX as your file type
  4. Select your desired phrase filtering options
  5. Select what language you want exported
  6. Select an export type of Phrases
  7. Click Export and your browser will download a copy of your new RESX file
  8. Repeat for each language you need in your mobile application
  9. Place a copy of each language file into the corresponding directory within your codebase and rename the file to Resources.es.resx (using the appropriate language code, Spanish used here) or simply update existing files with content from the new ones.

Test your localized mobile application

Now that your files are properly formatted and loaded into your mobile application, change the language of your simulator or live device to one of your newly installed languages and load up your application. You should see all content properly translated.

Xamarin.iOS Native Apps

Preparing your Xamarin.iOS native app for localization

When localizing the text content in your Xamarin.iOS native app you will be using Localizable.strings files which contain key=value pairs. You will create a separate Localizable.strings file for each language. The key for each phrase will be the same across all languages, so that the app can use the key to retrieve the appropriate translation.

"submit_button"="Submit"
"first_name_field"="First Name"
"last_name_field"="Last Name"

A language-specific Localizable.strings file will be stored within a directory named with the appropriate language code, e.g.: <language>.lproj.

If you have hard-coded any copy into your Xamarin.iOS native app directly, you will need to apply best practices and abstract your strings into a Localizable.strings file.

When a user’s mobile device is changed to a different language, your mobile application will attempt to load resources for that language by loading the appropriate language file. For example, if the mobile device is set to French your application will load resources from the fr.lproj directory.

Using the Localize Dashboard to translate your Xamarin.iOS Native App

Import your Localizable.strings file into Localize

  1. Within your Localize Dashboard go to the Phrases > File Import/Export page
  2. Select Import from the left submenu
  3. Select XCODE STRINGS as your file type
  4. Your source language will automatically be selected as the only language option
  5. Select an import type of Phrases
  6. Upload and submit the Localizable.strings file that contains your source language

Translate your imported phrases

Using the Localize dashboard, you may translate your source language phrases into as many languages as you need. If you are unfamiliar with the translation workflow, please see our Basic Translation Workflow with Localize video.

Export your translations into new Localizable.strings files

  1. Within your Localize Dashboard go to the Phrases > File Import/Export page
  2. Select Export from the left submenu
  3. Select XCODE STRINGS as your file type
  4. Select your desired phrase filtering options
  5. Select what language you want exported
  6. Select an export type of Phrases
  7. Click Export and your browser will download a copy of your new XCODE STRINGS file
  8. Repeat for each language you need in your mobile application
  9. Place a copy of each language file into the corresponding directory within your codebase and rename the file to Localizable.strings or simply update existing files with content from the new ones.

Test your localized mobile application

Now that your files are properly formatted and loaded into your mobile application, change the language of your simulator or live device to one of your newly installed languages and load up your application. You should see all content properly translated.

Xamarin.Android Native Apps

Preparing your Xamarin.Android native app for localization

When localizing the text content in your Xamarin.Android native app you will be using Strings.xml files. Each phrase contains a string XML element with the resource ID specified as the name attribute and the translated string as the value. The resource ID for each phrase will be the same across all languages, so that the app can use it to retrieve the appropriate translation.

<?xml version = "1.0" encoding="UTF-8"?>
<resources>
  <string name="submit_button">Submit</string>
  <string name="first_name_field">First Name</string>
  <string name="last_name_field">Last Name</string>
</resources>

You will create a separate Strings.xml file for each language. Each language-specific Strings.xml file will be stored within a directory named with the appropriate language code, e.g.: values-<language-code>.

If you have hard-coded any copy into your Xamarin.Android native app directly, you will need to apply best practices and abstract your strings into a Strings.xml file.

When a user’s mobile device is changed to a different language, your mobile application will attempt to load resources for that language by loading the appropriate language file. For example, if the mobile device is set to French your application will load resources from the values-fr directory.

Using the Localize Dashboard to translate your Xamarin.Android Native App

Import your Strings.xml source language file into Localize

  1. Within your Localize Dashboard go to the Phrases > File Import/Export page
  2. Select Import from the left submenu
  3. Select ANDROID XML as your file type
  4. Your source language will automatically be selected as the only language option
  5. Select an import type of Phrases
  6. Upload and submit the Strings.xml file that contains your source language

Translate your imported phrases

Using the Localize dashboard, you may translate your source language phrases into as many languages as you need. If you are unfamiliar with the translation workflow, please see our Basic Translation Workflow with Localize video.

Export your translations into new Strings.xml files

  1. Within your Localize Dashboard go to the Phrases > File Import/Export page
  2. Select Export from the left submenu
  3. Select ANDROID XML as your file type
  4. Select your desired phrase filtering options
  5. Select what language you want exported
  6. Select an export type of Phrases
  7. Click Export and your browser will download a copy of your new Strings.xml file
  8. Repeat for each language you need in your mobile application
  9. Place a copy of each language file into the corresponding directory within your codebase and rename the file to Strings.xml or simply update existing files with content from the new ones.

Test your localized mobile application

Now that your files are properly formatted and loaded into your mobile application, change the language of your simulator or live device to one of your newly installed languages and load up your application. You should see all content properly translated.

Add Localize to your build process

Localize REST API

You can integrate Localize into your build process by writing scripts that make RESTful HTTP requests using the Localize REST API for the import and export of localization files, as well as much more. Our route documentation provides examples of HTTP requests in cURL, Node, Ruby, JavaScript, and Python.

npm module

You may also use our npm module, @localize/node, a Node-based wrapper for Localize’s REST API.

Localize CLI

You can also use the Localize CLI which uses a simple push/pull paradigm to push content into Localize and then pull out the translations.
Read about the CLI at https://help.localizejs.com/docs/localize-cli

Updated about a month ago


Xamarin: How to use Localize to translate your Xamarin mobile application


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.