Apple Strings (.strings) is a text-based file format that is widely used in Apple's development ecosystem for storing localization data. It is built around a simple structure that consists of key-value pairs, where each key is a string identifier, and the corresponding value is the actual text or translation. Both the key and value are strings of text enclosed in double quotation marks, and are separated by an equals sign. The end of each key-value pair is marked by a semicolon.
"GeneralLearnMore" = "Learn more"; /* Common usage of the "Next" text. */ "GeneralNext" = "Next"; /* Common usage of the "Previous" text. */ "GeneralPrevious" = "Previous"; /* Common usage of the "Welcome <NAME>!" text. At runtime, the placeholder is replaced with a concrete value. Example: "Welcome John!" */ "GeneralWelcome" = "Welcome %s!"; /* Intro message split into two lines. */ "PageHomeIntro" = "Welcome to our website,\nwhere technology and innovation meet creativity and design."; /* Welcome message that includes the user's first and last name. */ "PageHomeSubtitle" = "Welcome %1$@ %2$@!"; /* Home page title */ "PageHomeTitle" = "Home";
Format specifiers are placeholders used to insert values into text dynamically. They are indicated by a percentage sign (
%) followed by a character that indicates the type of value to be inserted (e.g.,
%f, etc.). These placeholders work like formatting characters in
printf statements, which are commonly used in programming languages like C to format output.
Positional formatting specifiers allow you to specify the order in which variables are inserted into a string. They are denoted by a numbered index in the syntax, such as
%3$f. These specifiers are particularly useful in messages with multiple formatting specifiers, where the order of the specifiers might change during translation into different languages. By specifying the position of each variable, you can be sure that the correct variable is inserted in the correct place in the translated string.
In addition to specifying the order of variables in a string, you can also apply additional formatting options to format specifiers in Apple Strings file format. For example, you can use the “
%.2f” format specifier to indicate that a floating-point number should be formatted with two decimal places.
Here are some examples of formatting specifiers used in localization messages:
"UserWelcome" = "Welcome, %s!"; "UserNotification" = "The %1$s has assigned you a %2$s task."; "FormattedMathPi" = "Pi: %.2f";
A brief overview of the format specifiers:
Comments are used to provide additional information or context to translators or other developers who may be working with the file. They can be used to explain the purpose of a particular string, provide usage examples, or even to leave notes for future reference. Comments in .strings files are marked with the
// This is a single-line comment /* This is also a comment */ /* This is a multi-line comment.*/
Below are some examples of newlines in Apple Strings files.
"WelcomeMessage" = "Welcome!\nGlad to see you again!"; "WelcomeMessageExtended" = "Welcome! Glad to see you again! Hope you like our new design! ";
Certain characters need to be preceded by a backslash before they can be included in a string in Apple Strings file format. These characters include double quotation marks (
"), backslash character (
\), and special control characters such as linefeed (
\n) and carriage returns (
The most common mistakes when working with Apple Strings files include not properly escaping characters, using the wrong encoding, not using placeholders correctly, and not translating all strings.
Pluralization is not supported in Apple Strings files. To handle plurals correctly, you should use a strings dictionary (.stringsdict) file format.
Tired of manually editing translation files?
Our platform streamlines software localization for you.