jonathanpenn/ui-screen-shooter

locale is not always same as language

Closed this issue · 5 comments

For the United States, language = 'en' but locale should be 'en_US'. I noticed this when some code I use to get the currency symbol would return an unexpected string:

    NSString *currencySymbol = [currentUserLocale objectForKey:NSLocaleCurrencySymbol];

I tracked the problem down to chose_sim_language, setting locale='en' caused the bad currency symbol.

I made the following modification to chose_sim_language which solved my problem:

    # Create the language array with just the given language
    # Special case for US locale != language:
    if [[ $1 == "en" ]]; then
        locale="en_US"
    else
        locale = $1
    fi
    _plistbuddy "$file" \
    -c "Add :AppleLanguages array" \
    -c "Add :AppleLanguages:0 string '$1'" \
    -c "Add :AppleLocale string '$locale'"

I didn't delve into this issue too much further other than to solve my own problem, but I presume that UK developers would need a similar if-then for 'en_GB'.

The above was tested using xcode 5 and iOS7.

@kenl97216 you can also just use languages="en_US", using just "en" will change the language, but not the region format.

I think this is the full list of locales currently on iOS 7: https://gist.github.com/knorrium/6604326

Thanks @kenl97216 for pointing this out. I think you've hit on a larger problem that will also affect other locale's as well, not just the US. I think instead of doing the if statement that you mentioned, we should change the list of locales that get looped over in run_screenshooter.sh so that more specific locale identifiers are used. I'm going to update the script to use en_US.

I didn't even think of trying en_US, if that works then that's probably better than my if...then hack. Kinda busy today (something about a new OS available I hear...) but I'll verify asap.

Oh, yes. We're all quite busy. :) Thanks for doing the research on this!

I verified that en_US works.