It is backward compatible for for .xcstrings files converted from .strings files. It means the same R.string codes will be generated.
However, it is not backward compatible for .xcstrings files converted from .stringsdict files, because of named arguments.
About named arguments
My implementation strips names of substitutions from generated arguments. I found using them problematic on some cases.
In my opinion, named arguments does not worth the implementation. Xcode generates substituons only if there are more than one pluralable parameter on new xcstrings files. The most of the string values will not be have any information to generate named arguments.
Problematic case 1
Some key information is lost on the xcstring convertion of stringsdict files.
Original stringsdict content.
This strings value is "1 iPhone and 10 touches" on iPhones and "1 Mac and 10 keys" on Mac.
There are 2 substitutions for each device variation.
Which signature should we use?
.example(device_iphone: Int, input_iphone: Int)
.example(device_mac: Int, inputmac: Int)
.example( arg1: Int, _ arg2: Int)
.example(device Int, input: Int) //With some extra coding to detect shared parts of the names.
About algorithm
The alghorithm tries to convert localization of source language to single string with basic format parameters, then it uses FormatPart.formatParts(formatString:)` on this string to extract parameters.
This convertion works like that:
If localization has stringUnit, get its value, and replace the substitutions inside if.
Else if localization has variations for device or plural, convert each variation value to string with the same algorithm and select the string with most parameters. (To work correctly, all variations should have same parameters, but on some cases such as plural rule one or zero, parameter may not be used)
Substitutions replacement works like that:
Substitutions generated by Xcode contain plural variations with %arg parameter. Each substitutions has argNum and formatSpecifier variable to define real properties of this %arg parameter.
The value of a substitution is calculated by the convertion algorith above.
Then, %arg parameters on the calculated value is replaced according to argNum and formatSpecifier values.
I did a simple development for xcstrings support.
It is backward compatible for for
.xcstrings
files converted from.strings
files. It means the same R.string codes will be generated.However, it is not backward compatible for
.xcstrings
files converted from.stringsdict
files, because of named arguments.About named arguments
My implementation strips names of substitutions from generated arguments. I found using them problematic on some cases.
In my opinion, named arguments does not worth the implementation. Xcode generates substituons only if there are more than one pluralable parameter on new xcstrings files. The most of the string values will not be have any information to generate named arguments.
Problematic case 1
Some key information is lost on the xcstring convertion of stringsdict files. Original stringsdict content.
Generated xcstrings content
R.swift creates .x_users(users: Int) for stringsdict file. However, xcstrings file does not have the argument name information any more.
If string value of the original content is
<string>Add %#@users@</string>
, generated xcstrings would keep the substitution information.Problematic case 2
This strings value is "1 iPhone and 10 touches" on iPhones and "1 Mac and 10 keys" on Mac. There are 2 substitutions for each device variation. Which signature should we use? .example(device_iphone: Int, input_iphone: Int) .example(device_mac: Int, inputmac: Int) .example( arg1: Int, _ arg2: Int) .example(device Int, input: Int) //With some extra coding to detect shared parts of the names.
About algorithm
The alghorithm tries to convert localization of source language to single string with basic format parameters, then it uses FormatPart.formatParts(formatString:)` on this string to extract parameters.
This convertion works like that:
Substitutions replacement works like that:
Example 1
Example 2
Example 3
%#@books@ and %#@pens@
%arg book
%1$lld book
%1$lld book and %#@pens@
%arg pen
%2$lld pen
%1$lld book and%2$lld pen
%1$lld book and %2$lld pen
. [%lld, %lld]