Printing the locale names - iphone

I want to know and print the locale names which I am changing on my device. Is there any way to print them. Printing a NSLocale object does not help.

Create an NSLocale for the language in which you want the words to appear, then use -displayNameForKey:value: on the NSLocale object to get the display name for the NSLocaleIdentifier key.
The documentation for this method has an example that shows you exactly what you're looking for.

Related

LIst of all region format

i'm be able to retrieve the region format of the user, ad example it_IT with this code
[NSLocale currentLocale] objectForKey:NSLocaleIdentifier];
is it possible have the complete list of these identifier?
(it_IT, de_DE, de_AT,....)
Thanks
[NSLocale availableLocaleIdentifiers] is yet another way.
For testing, specifically to insure all date formats are handled properly in my UI, I rip through that array, set a NSDateFormatter to use that and test for every possible combination of date formatting in an automated way.
Interesting what you learn along the way as well when you see some date representations that break your assumptions about how some dates, day names, etc might be formatted.
Try with this:
Returns an array of NSString objects that represents all known legal ISO currency codes.
[NSLocale ISOCurrencyCodes];
Returns an array of NSString objects that represents all known legal country codes.
[NSLocal ISOCountryCodes];
Returns an array of NSString objects that represents all known legal ISO language codes.
[NSLocale ISOLanguageCodes];
All the info from:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSLocale_Class/Reference/Reference.html

Customizing phone number or any other String for different Locales in GWT

I am trying to find the best route to get in some Custom formats I need. For example if I have a phone number 0803456765
In India it may be represented as +91 (080) 3456765
In US it may be 080-345-6765 and so on
I could keep the format in the properties file and based on locale I could pull the format and format the String. I could also have a Util class which does this for me after I identify the Locale.
But I think there might be a better route using NumberFormat. I guess NumberFormat automatically figures out the Locale and applies a certain Pattern to the String. Can I customize this pattern ? In the sense, can I tell GWT to use my Custom pattern for the US Locale
I know we can do this
// Custom format
value = 12345.6789;
formatted = NumberFormat.getFormat("000000.000000").format(value);
// prints 012345.678900 in the default locale
GWT.log("Formatted string is" + formatted, null);
but I don't want to specify my formatting pattern as in 'NumberFormat.getFormat("000000.000000")'. I want to override the default number formats of various Locales in GWT to achieve this. How do I do this ?
Don't roll your own. Google open sourced their library which you can leverage. It supports
Parsing/formatting/validating phone numbers for all countries/regions
of the world.

Is NSLocalizedString() based on the user's language or their region setting?

I am localizing my app for Denmark. I have the Localizable.Strings and the XIBs translated into Danish.
On iPhone a user can
Set the 'Region Format' to 'Denmark'
but keep the language 'English'
Set the 'Region Format' to any English-speaking country but keep
the language 'Dansk'
Set the 'Region Format' to 'Denmark' and language 'Dansk'
My question is: for any of the above settings should the app show the 'Danish' version (which for my App will mean all text in UI and the database to be in Danish.) or should the 'Danish' version only come when user sets the language to 'Dansk'?
This is a great question.
The real issue it comes down to is, in Apple's opinion, as they did it, does NSLocalizedString tend to favour the 'Region Format' or the 'language' setting?
I have never been able to find a clear answer on this, I just let NSLocalizedString decide.
(Purely FWIW, I think follow the "language" setting.)
It's possible the following code snippets could help you.
// to ("usually") get the preferred language FROM THE SET WHICH we supplied in bundle
// [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0]
// to ("often") get the preferred language REGARDLESS OF what we supplied
// [ [NSBundle preferredLocalizationsFromArray:[NSLocale ISOCountryCodes]] objectAtIndex:0]
// to ("fairly reliably") get the user's chosen language setting...
// [ [NSLocale preferredLanguages] objectAtIndex:0]
It may not help, but I hope it helps.
Languages and locales are treated differently by Cocoa, because they are independent concepts. NSLocalizedString() will obey the current language setting of the OS, where things like dates, times, and numbers are affected by the locale setting.
Why locales are handled separately from languages can be found in the Locales Programming Guide:
When you display data to a user it
should be formatted according to the
conventions of the user’s native
country, region, or culture.
Conversely, when users enter data,
they may do so according to their own
customs or preferences. Locale objects
are used to provide information
required to localize the presentation
or interpretation of data. This
information can include decimal
separators, date formats, and units of
measurement, as well as language and
region information.
For example, by convention in the
United States “7/4/76” represents the
Bicentennial of the Declaration of
Independence. However, in Great
Britain, it represents the “7th of
April, 1976”; in Thailand using the
Thai Traditional Calendar it might
represent “April 7th, 2519”; and in
France it represents “7 avril 1976”.
To take a more subtle example, in the
United States“12.125” represents the
decimal number twelve and one eighth,
whereas in Germany it represents
twelve thousand one hundred and
twenty-five.
In the example given there, you might have a user who prefers to use English as their primary language, yet who lives in Germany and is used to a comma as a decimal separator, not a period.
The Internationalization Programming Topics guide has a lengthy discussion of all the issues involved and how to deal with them.

How to get an string representation from an NSDecimal without any formatting?

For example, I have an NSDecimal myDecimal. Lets say it represents something like "-1234567.89"
How can I get a clean string representation of that decimal without any beautification / formatting? No localization? Floating point symbol = . and rest only numbers from 0 to 9, and eventually an - if it is negative? I need that string in strict technical manner. A number like 123456789876554432123456789.2231 should therefore not look like nice formatted "123,456,789,876,554,432,123,456,789.2231". You get the point right?
I don't want any formatting. I'm trying all day now to get that right but everything I find always has to do with formatting. So how'd you guys do that?
I don't believe there is such a thing as a "clean" string representation independent of specifying the locale. As many Europeans would point out, 123.45 should be written as 123,45 (using , instead of . for the decimal location). NSDecimalString() (which can be found in the Foundation Functions Reference) takes, as a second parameter a locale specification. If some locale uses the format you desire, pass that locale as the second parameter (see the Internationalization Guide for more info on locales).
Alternatively, you can use an NSNumberFormatter, which will give you more controll over the string representation.
For easy (localized) control use an NSNumberFormatter.
float number = 12.345;
NSString* numberString = [NSString stringWithFormat:#"%f", number];
That will give you consistent formatting regardless of the user's current locale.

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this
279498721.322872
I am using Objective C in an Iphone App. Does anyone know how to make this export out as a regular date whether it is all number like
2009-02-10 or anything legible?
Well, if you take the number 279498721.322872 and throw it into an NSDate object using +dateWithTimeIntervalSinceReferenceDate, you get (here in the MDT timezone): 2009-11-09 15:32:01 -0700, which was just under 4 hours ago. If that's the time you're expecting, then formatting it is as simple as using an NSDateFormatter.
However, the thing to notice is that sqlite (by default) stores dates as textual representations (unless you specify differently in the sql statement). So the real question here is "where are you getting that number from?"
echo date("Y-m-d",time(279498721.322872));
Thanks for the responses. The answer came from my Guru Alex Cone. He told me to use the following:
NSTimeInterval tempInterval = (NSTimeInterval)sqlite3_column_double(statement, 4);
The tempInterval variable can then be loaded into the the NSDate method.