Apple Strings and Stringsdict
Apple Strings and Stringsdict are used to localize strings in Apple platforms. The format is currently deprecated. However, we still recommend using it in favor of XLIFF since this Strings and Stringsdict gives you better control over the strings and their translations.
The .strings
file is used to store simple strings, while .stringsdict
is used to store only the plural values.
Example of a Strings file:
/*
Localizable.strings
*/
/* This is a comment */
"welcome_header_%@" = "Hello, %@";
/* This is a comment */
"user_settings_password_label" = "Password";
Example of a Stringsdict file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>what-a-key-plural_%lld</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@format@</string>
<key>format</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>lld</string>
<key>one</key>
<string>Peter has one dog</string>
<key>other</key>
<string>Peter hase %lld dogs</string>
</dict>
</dict>
</dict>
</plist>
We recommend using the semantic keys format as in the examples above. That enables you to change the base values without modifying the actual key and doesn't suggest keeping the keys in sync with the base language translation.
The MessageFormat and placeholder conversion
When importing data to Tolgee from the Apple .strings and .stringsdict files, you can either enable or disable the conversion to the Tolgee Universal ICU placeholders. The conversion is enabled by default. You can also disable the conversion globally in the project settings. We recommend keeping the conversion enabled, as it brings many benefits. Read more about the benefits of Tolgee Universal ICU placeholders.
When the conversion is disabled, the original placeholders (e.g., %llm
, %@
). are preserved. The message format is automatically detected when importing data in Apple .strings and .stringsdict format. When exporting, you can choose from message & placeholder formats listed above.
Placeholder conversion specification
The official Apple's string format specifiers documentation can be found here.
Only specifiers specified in the table below are supported. Tolgee doesn't support additional flags and modifiers and placeholders using them are not converted.
Specifier | ICU type | Example | Converted to ICU | Note |
---|---|---|---|---|
% | N/A | %% | % | %% is the way how to render %, in ICU we don't have such concept, so we just add %. When exporting, the % is converted back to %%. |
@ | none | %@ | {0} | |
lld | number | %lld | {0, number} | |
f | number, [precision string] | %f | {0, number, 0.000000} | By default %f uses 6 decimal places, that's why we convert it to the number with such precision. %.2 f would be {0, number, 0.00} and so on. |
e | number, scientific | %e | {0, number, scientific} | %E is not supported |
If your placeholder is not supported, you can use %@
and format the string yourself in the code.
Apple also supports n$
positional specifiers. There are converted to as well as the zero based argument index. E.g.
I am %2$@, and I have %1$lld dogs.
is converted to I am {1} and I have {0, number} dogs
.
Importing / Exporting in general
To read more about importing and exporting with Tolgee, continue to import section or export section.