I have app in android studio and When i install APK and Language is English,
it show language of app like i want, but when phone language is different like Persian, it show other language in app and i don't want it...
how i can force app to use same English even language of phone changed?
my application is in Android studio and just one line have problem, mean there is a line words in application, and when i change language phone, it change to a different language same i don't want.
this is my main.xml (same line code
<TextView
android:id="#+id/diffText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dhuhar After one hour 10 min"
android:textColor="#ffffff"
android:textSize="16dip"
android:textStyle="bold"></TextView>
</LinearLayout>
And this one is not available in my string.xml, it mean it not translated, correct?
and cause "one hour 10min" is not stable, there is easy way i force it to use for all language same use for english?
I set below code in oncreate and solved
Locale.setDefault(Locale.ENGLISH);
If you want only english for all languages, dont set different language xml.. Just provide only default strings.xml.. app will show what ever text in strings.xml.
If you don't define your string in other language files (only write <string name="yourstring" translatable="false">Your english string</string>) then you will get your expected behavior.
That is because it takes the strings from values/ if they are not available in the specific folder for the current language (e.g. values-de/)
Related
I have the following TextView within a ConstraintLayout:
<TextView
android:id="#+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="3"
android:textAppearance="#style/TextAppearance.AppCompat.Title"
... />
When the text is too long to fit in one line, it will break into two lines. However, if the system language is set to Swedish it will break in the middle of words without adding a hyphen, like so:
Some text that is br
oken into two lines
I'm not sure if this is an accurate example, but you get the idea.
What I want is this:
Some text that is br-
oken into two lines
It does work when the system language is set to English. But it should also work for Swedish.
I have tried all possible combinations of android:breakStrategy="..." and android:hyphenationFrequency="..." on the TextView.
compileSdkVersion 28
targetSdkVersion 28
minSdkVersion 28
I think that the problem comes from localization and characters encoding in different languages.
I suppose you are using the translation editor to support localization. Try getting the string of each textView (etc...) and converting it to utf-8 format using this:
URLEncoder.encode(your string, "utf-8");
Then set the textView text to this string:
textView.setText(your string);
Hyphens are only added to connect words in line breaks if the language is set to English. This is probably a bug. Source: https://issuetracker.google.com/issues/37087785 https://issuetracker.google.com/issues/37010641 https://issuetracker.google.com/issues/79936443
Not every languages is available for hyphenation in every Android version. E.g. Swedish and Polish are not available in Android API 33; they should be with the following Android release.
To perform proper hyphenation Android needs the language "dictionary" which are stored here: https://cs.android.com/android/platform/superproject/+/master:external/hyphenation-patterns/;l=1?q=hyphenation-&sq=
When it doesn't have the language dictionary available, it tries to break as best as it can, based on the available space.
When I change the device language, strings that are not in the strings.xml are showing in my text view.
Below is my text view code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="#dimen/padding_all_activity_16"
android:text="#string/check_document_image_readable"
android:textSize="18sp"
android:textStyle="bold" />
......
in the values/string.xml file:
<string name="check_document_image_readable">A foto ficou legível?</string>
My app don't support other languages (it is written in portuguese).
When I run the app withe the device set to English:
But if I change to Spanish (even if I kill the App):
I'm developing with Android Studio 3.0.1. This happens in the API's 24 and 25.
How can I use only the values/strings.xml for any device language?
Android has support to Different Languages and Culturesaccording to the device's language setup. You can achieve that working with different strings resource for which language that you desire to support.
In your project, right-click res/values/ and select New -> Values resource file. Enter "strings" for the file name and leave the source option set to main. In the Available qualifiers and click ">>" button to move "Locale"to the Chosen qualifiers section. Select the language that you wish to support and select the region (default is: Any region) and left-click "Ok". Android studio will automatically generate a new resource file also called "strings.xml".
Why did I mention that? Android at run time looks for a default string resource. What might be happening is that you're not using a default string resource, instead you're using a 'string-pt' resource, this would be a problem if you don't have resource string file for Spanish or other language.
if you intend to support other languages when the user changes the default language.
you should override string.xml file
create another string.xml (sp) with Spanish as local and add your resource value
<resources>
<string name="check_document_image_readable">A foto ficou legível?</string>
</resources>
to override string.xml with the Spanish version.
click on the res folder choose new resource file and name it strings.
on the left select local and choose Spanish
As I asked in the following question:
Arabic number in Arabic text in Android
if I use the arabic locale ar-ae or ar-sa the numbers are shown using Hindu-Arabic numbers.
I need to show the digits like in English: "1234567890".
I used to use the trick of setting the numeral extension
Locale.Builder builder = new Locale.Builder();
builder.setLocale(savedLocale).setExtension(Locale.UNICODE_LOCALE_EXTENSION, "nu-latn");
Locale locale = builder.build();
The problem is that after you do that the resource lookup gets broken and with Nougat it just does not work anymore.
Is there a way to see the "normal" digits even using the Arabic locale for ae and sa?
One workaround is to replace the font for the digit characters. You'll be able to keep your original font for the text.
I would recommend to do that in a clean way by extending TypeFaceSpan.
Take a look at this question.
If you need some code, let me know and I'll update this answer.
You should trust the locale you are using. If you are specifically targetting ar_SA then you should let it render things the way it's meant to for that country. If you just want Arabic language but want the western Arabic numbers then try a locale from one of the western Arab countries, ar_MA for example.
For now what I did is to use a custom font and to replace in the file for the custom font the digits with the Hindu-Arabic numbers with the correspondent char for the "western-Arabic" number.
Please check
how to remove characters from a font file?
EDIT
It is now possible to use a locale like for example:
<item>ar-AE-u-nu-latn</item> <!-- Arabic (United Arab Emirates, Western Digits) -->
This is taken from here
i am currently working on one Android Application and i have to set layout according to country like if application is for Korea layout color must be blue and for india layout color must be red.
So how can i achieve that?
i know about multiple language
values-kr // for Korea
values //for English
values-fr // for french
but for layout i don't know.
Help Me.
Thanks in Advance
You can create a Style for each Values or in java code programming you can use a simple if statement that detects your location inside "oncreate method" and setbackground layout according to what you want using a drawable.
You have to determine your system language. You can use
Locale.getDefault().getLanguage();
to get the usual language code (e.g. "de", "en").
Then, create a base Activity for your app and override onCreate to set the theme according to your system language. Derive all your other activities from this base Activity. Check this tutorial.
follow type of languages
res/values/strings.xml
Contains English text for all the strings that the application uses,
including text for a string named title.
res/values-fr/strings.xml
Contain French text for all the strings, including title.
res/values-ja/strings.xml
Contain Japanese text for all the strings except title.
How to display Korean Words in android app
You may use this piece of code:
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String locale = tm.getSimCountryIso();
and choose:
if (locale.equals(pk))
{
view = inflater.inflate(R.layout.hazel_quick_form, container, false);
} //fragment
Take example of TextView.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:textColor="#color/textcolor" />
you can have colors.xml file in different locale folders like values , values-fr etc.
In example textview #color/textcolor can be defined with those saperated colors.xml files with different colors for different locales.
look at this.
Android will do the next magic automatically based on locale.
Background
Lint has a relatively new feature, so that it will warn us about missing translation only for languages that we choose, but i don't get how to use it.
The problem
for some reason, Lint still warns me about languages that i don't intend on translating yet.
What i've tried
for example, currently i want to only have 2 languages : english ("en") and hebrew (which is sadly both "iw" and "he" ) .
so i have strings files in the folders :
values (for english)
"values-he" and "values-iw" (for hebrew) .
i've tried putting the new attribute in the english file as such :
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="en,iw,he">
...
The question
what is the right way to do it?
Looking here it seems that it's to be used into resource files to indicate the default language. So you can specify only one locale code.
should correspond to a language
Moreover it seems to be used only to disable spell-checker
If you read the article:
This lets you tell the tools which language you're using in your
base values folder. For strings in for example values-de or values-en it's obvious, but not in the base "values" folder
It need only to know what is the language in the default "values" folder (the folder without any attribute).
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="en">
You are already in right direction. Just need some modification. Like this manner:
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="es">
Now we know that the language used for strings in the default values folder is Spanish rather than English.
Used by: Lint, Studio (to disable spell checking in non-English resource files)
Reference Link: Go to here tools:locale
Thanks.