We've launched a new support center at help.smartling.com. This site will continue to be maintained into January 2017. Please update your bookmarks.
Follow

Adopting the Smartling iOS Plurals Library

The following article applies to Application Resource Files project types. 

Smartling has built an open source library to support plurals for iOS applications. The following instructions walk you through the process of integrating the library and plurals with your application.

Background

While iOS files do not normally support plurals, Smartling has extended the format by developing an open source library to accommodate plurals. For more information about plural file formats in Smartling, see About Plurals.

Step by Step Guide

  1. Download and Integrate the Smartling iOS Library into your Application.
    Download the latest library from the Smartling github page and follow the instructions here: https://github.com/Smartling/ios-i18n#installation
    Please review the documentation on github for details on required project build configuration settings.
  2. Update Your String Files With Plural Indicators
    To detect plurals, you must append a key with “##{pluralTag}” where pluralTag is zero, one, two, few, many and other. For example, for an English-based strings file, a sample plural set of strings looks like:
    /* Number of songs from search results */
    "%d songs found##{one}" = "One song found";
    "%d songs found##{other}" = "%d songs found";

    The pluralTags depend on the source language and you should consult the CLDR plural rules to determine which tags to use for your source locale.

    Like other file formats that support plurals, keep the various plural forms for a key together within the file. This ensures proper linkage when Smartling provides translations.

    Note: You can add your plurals strings to any file you have already built by hand or append them to a genstrings-created file. 

  3. Replace Calls of NSLocalizedString with Calls to SLPluralizedString
    All the newly defined plural strings need to be invoked with the SLPluralizedString class from the Smartling i18 framework. SLPluralizedString takes one additional parameter which is the variable used to determine the pluralTag at runtime, and the library determines which pluralTag should be used based on the locale.

  4. Have Your Strings Translated
    Much like your source strings file, the files for your target languages need to have the correct pluralTags according to the CLDR plural rules. Your best bet to get this right is to upload the file to Smartling where your translators (or ours if you don’t have your own), will complete the translations. Don’t worry, Smartling insists that it has all the correct forms plural forms. Once translated, simply copy the files back into your application as you normally would. (The files are named the same, are in language subfolders such as en.lproj/ or ru.lproj/)

    Your localized strings file (for example, Russian) looks something like this:

    /* Number of songs from search results */
    "%d songs found##{one}" = "Найдена одна песня";
    "%d songs found##{few}" = "Найдено %d песни";
    "%d songs found##{many}" = "Найдено %d песен";
    "%d songs found##{other}" = "Найдено %d песен";

  5. Migrate from Hard-Coded Logic with Unique Keys
    If you already have hard-coded plural logic into your application with unique strings, you may need to adjust the keys that you are using and migrate from NSLocalizedString to SLPluralizedString. For example, if you have keys, “songs_found_singular” and “songs_found_plural” with logic in your code to switch between the two, you will need to normalize them to “songs_found##{one}” and “songs_found##{other}” and use SLPluralizedString with “songs_found” (it will pick the right one for you).

  6. Tweet Us
    We want to know your thoughts on the library. Tweet us (@Smartling).



Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request
Powered by Zendesk