tolgee / tolgee-platform

Developer & translator friendly web-based localization platform
https://tolgee.io
Other
1.95k stars 201 forks source link

Apple .stringsdict (plurals) not usable after export #2189

Closed awatke closed 8 months ago

awatke commented 8 months ago

Hello,

I think there is an issue with the export of apple .stringsdict.

If I have a placeholder for numbers like %d, but after the export I can't use it. There 2 missing keys in the exported dict (NSStringFormatSpecTypeKey and NSStringFormatValueTypeKey).

This is the exported result:

<?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>NSStringLocalizedFormatKey</key>
    <string>%#${#@format@}</string>
    <key>format</key>
    <dict>
        <key>one</key>
        <string>One home found</string>
                <key>other</key>
        <string>%d homes found</string>
    </dict>
</dict>
</plist>

and this is the expected result:

<?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>NSStringLocalizedFormatKey</key>
    <string>%#@format@</string>
    <key>format</key>
    <dict>
        <key>NSStringFormatSpecTypeKey</key>
        <string>NSStringPluralRuleType</string>
        <key>NSStringFormatValueTypeKey</key>
        <string>d</string>
        <key>one</key>
        <string>One home found</string>
        <key>other</key>
        <string>%d homes found</string>
    </dict>
</dict>
</plist>

see: https://developer.apple.com/documentation/xcode/localizing-strings-that-contain-plurals

Can anybody check this?

And if I change the plurals variable name in tolgee, I don't see this changes in the exported dict. Is that also a bug?

JanCizmar commented 8 months ago

Hello! Thanks for reporting.

<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>

We've probably not exporting this sequence correctly. It's a bug.

The plural variable name stored in Tolgee wasn't intended to be exorted to .stringsdict file, since it doesn't seem to have any meaning in the .stringsdict context. Am I mistaken?

awatke commented 8 months ago

Thanks for the quick response.

What exactly is the variable for?

And there are 2 missing keys not only NSStringFormatSpecTypeKey:

<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
JanCizmar commented 8 months ago

From apple docs:

Furthermore, using the NSStringFormatValueTypeKey format specifier in the localized formatted strings is optional. For example, the format string for the one category in English can be One home found, while the other category can be %d homes found.

So I guess, we can omit it. However, I will test the export output with real XCode project.

What exactly is the variable for?

When you export to ICU or other formats supporting named properties, this is the name of the plural variable. e.g. Variable name: count will be exported in ICU plural as: {count, plural, one {I have one dog} other {I have # dogs}}

JanCizmar commented 8 months ago

OK, so according to my testing, the NSStringFormatValueTypeKeyisn't optional. We will have to add it too.