NSDateIntervalFormatter android counterpart? - android

Any one known how to format a date range with respect to different language and locale setting in android? like NSDateIntervalFormatter in iOS do?

See formatDateRange in android.text.format.DateUtils
(http://developer.android.com/reference/android/text/format/DateUtils.html)

Related

Android format date using X country translation

For date parsing, I'm using SimpleDateFormat.
I know that it's possible to pass Locale object to translate month names.
I tried to use the Estonian language: Locale("ee", "Estonia"), but it did not work.
Am I using the wrong language code or Estonian language is not supported thus I've to use a different approach?
I was able to use Estonian by using:
Locale("et", "ee")
You can get the correct Locale for any country from Translations Editor in Android studio.
For Estonian country, Locale should be Locale("et", "ee")

Whats the standard approach to using region specific strings?

The app I work on will be launched in the UK, US and AU. I have strings.xml in values-en-rUS , values-en-rAU and values folders. I have certain strings for ex "Zipcode" which will only be used in the US so I have added them to strings.xml in values-en-rUS. I have "Postcode" as the equivalent in AU and UK strings.xml files.
This works fine as long as the device locale is set correctly ie, English(United states) in United states. If the device is in English (Australia) and the user is using the app in United states the solution fails.
Is there a standard approach for displaying a specific string irrespective of the device locale? Any help is appreciated
I think you are using the wrong localization.
values-en-rUS you are defining resources in english (locale en) for mobiles situated in the US region.
If you use values-en_US instead it should correctly work for the locale en_US.
To better understand how the fallback between the different locales will happen consider this link:
Android doc
The correct Java SE standard usage is:
Locale: Properties file name part:
Locale("en", "US") values_en_US
Locale("en", "AUS") values_en_AUS
Locale("en", "UK") values_en_UK
Best have a Locale("en") / values_en and values too.
There are some Locale constants. A small prototype will see whether this works satisfactory.

How to keep currency (keeping it localized) independent from system locale on android app?

I've been researching for a solution to this issue for a while and could not find a proper solution. The closest I've got was this entry from stackoverflow. But since this was asked 4 years ago (and is not actually my issue although it could help to solve my problem), I 'll ask again to see if now there is a better workaround.
Context:
I want to release my android app in several countries. Currently only available in Spain. I've read all android developers documentation about localization. It is pretty clear that all dynamic localized information on code should be based on "system locale" when presenting it to the user.
Problem:
Problem comes when user changes language on settings manually and I want to display a price (generated by the app) that bases it's currency on system locale preference. For example lets say I live in Spain and I set up my device Language & input/Language to English(United States). When I do this my app shows prices in US dollars ($) but I want it to keep showing EUR (€) since I'm in Spain. How do I achieve this?
This is mi actual code for showing a "localized" price to the user based on system locale:
Locale currentLocale = Locale.getDefault();
priceFormat = NumberFormat.getInstance(currentLocale);
localCurrency = Currency.getInstance(current);
//...
//doubleValueCost is independent from currency but the I want to add the proper currency symbol
costTextView.setText(priceFormat.format(doubleValueCost) + " " + localCurrency.getSymbol());
This code will add the currency symbol for the system locale selected by user on preferences and not the actual currency symbol of the country where the device is.
Any advice is welcomed. Thanks in advance.
After all the research I decided to use TelephonyManager simCountryIso to localize currency in the concrete scenario I mention in my problem. Not sure if it is the best solution to solve my proble but is the best option I've found. This would be the code to get the currency I need:
String countryIso = telephonyManager.getSimCountryIso();
localCurrency = Currency.getInstance(new Locale(countryIso,countryIso));
//doubleValueCost is independent from currency but the I want to add the proper currency symbol ...
costTextView.setText(priceFormat.format(doubleValueCost) + " " + localCurrency.getSymbol());
If anyone comes up with a better solution, I would be glad to hear.
Thanks
specifying the desired locale, for example this code to force the locale to Spain:
priceFormat = NumberFormat.getInstance(new Locale("es", "ES");
should do what you need.
Locale.getDefault() is loading the user defined locale

Way to type any language and appears exactly the same in Android?

I am making an app which shows an Indian Language (Punjabi). Is it possible if it shows exactly the same text on all the Android devices if my TextView is something like this: "ੴ ਸਤਿ ਨਾਮੁ ਕਰਤਾ ਪੁਰਖੁ ਨਿਰਭਉ ਨਿਰਵੈਰੁ ਅਕਾਲ ਮੂਰਤਿ ਅਜੂਨੀ ਸੈਭੰ ਗੁਰ ਪ੍ਰਸਾਦਿ " If not what's the best way to approach this?
If the file is encoded using UTF-8, you should be fine. But, don't forget that Android devices support multiple locales, so providing a translation is a good idea (unless you limit distribution to that locality).

force Time.format(...) to use local resources in android

android.text.format.Time uses System resources for getting month names, week days, etc. Now, I want to use my app in a locale that translations for that locale does not exist by default. Suppose I want to set custom names for weekdays. So, how can I use Time.format(...) method? How can I force it to use my resources instead of System's.
Any help will be appreciated, thanks.
You can define custom formats using either android.text.format.DateFormat or java.text.SimpleDateFormat. The latter lets you pass a custom DateFormatSymbols object, which should allow you to define your own names for months and weekdays, etc.

Categories

Resources