This may be a completely n00b question, but does Eclipse offer a way for me to use German umlauts in String resource files (res/values/strings.xml) without having to use their UTF-8 codes? Like to define a different charset for the XML file or whatever, being able to type in 'native' German language?
The reason why I'm asking is that writing and proof-reading a larger strings with UTF-8 codes in every 2nd word file causes extreme headaches and is prone for typos.
Related
The motivation of this question comes from this other question:
How do I get the current language my app is in? (Not the device's language as specified in the Settings. I want the language that Android resolved to use for my app).
This question has been asked several times on the site, but it fails to consider this corner-case:
Imagine the user has only one preferred language in his device: say German, for example.
My app two strings.xml files: The default one, and one in French (values-fr/strings.xml).
Obviously, Android will resolve to use the default strings.xml in this case.
But if I do any of the following, it will return German:
Locale.getDefault()
getResources().getConfiguration().getLocales().get(0)
getResources().getConfiguration().locale.
(And many other suggestions that I have found on the site)
And who told Android that the default strings.xml file was in German? Why did it made that assumption? The default file could be in Spanish, Italian, Polish...whatever.
Ideally, I would like a method that returns null in this case. Some method that tells me that no match was found for German and Android had to fall-back to the default strings.xml.
Does such method exist?
Put the language name in both strings.xml files. For example, as languageName.
When you get the string for R.string.languageName, it will be the language chosen by Android among the ones you support.
Those functions all return the phone's locale. They have nothing to do with resource localization. So nobody said the strings.xml file was German. The user set the phone to German, and the resource subsystem decided strings.xml was the best match for that. Basically you have the way it works backwards.
I don't think there is a way to get what you want for two reasons:
1)It's supposed to be transparent to the programmer.
2)It doesn't pick one file over the other. It picks independently for each string. So if you have a strings.xml with two strings A and B, and had a german strings file with only A, it would give you the german A and the default B.
I have ÷ in .txt file in my android. When this division symbol is shown on android device, I see "�"
To make it worse, my laptop doesn't have division sign on keyboard. I used the above sign from wikipedia.
Any guess how can I resolve this.
You should use the Unicode value for any symbols such as the division symbol you have here.
Try the Unicode U00F7.
When using it within a String format like "\u00F7".
The problem is most likely a font issue, or possibly a unicode encoding issue. The character you pasted is unicode codepoint 0xF7: if the font being used to display your text file does not have a specific glyph for this codepoint, then it will render it using some reserved glyph like the question mark diamond you show. The solution in this case would be to install and use a font which includes an appropriate glyph for this codepoint. For instance, if it is displayed correctly in your web browser, then find out what font your browser is using, and try that. Of course, whether or not you can change the font used to display your text file depends on the application (at least I think: I don't think Android fixes the font across all apps).
Alternatively, it could be an encoding problem. For instance, if you're saving your text file in Latin-1 encoding, then this character will be stored in a single byte with value 0xF7. If the app that you're viewing the file with is assuming it's UTF-8, for instance, then this byte will be interpreted as the first of a multi-byte character, or it may even be invalid. If this is the case, you just need to make sure the encoding you use to save the file is the same as the one being used to display the file. Again, this would be application specific.
I need to support multiple languages in my native app. I could properly create strings.xml file in their respective folders for various languages (Italian, Spanish, Portuguese, etc.). However, I have tough time in creating strings.xml under values-ja folder for Japanese language.
I have strings in japanese font in word document. When I copy these strings to strings.xml file in eclipse, the strings are replaced with junk characters (i assume it is due to japanese font missing in eclipse or wrong encoding). I googled for hours but couldn't find a way to fix it.
any help will be appreciated.
You have to save the strings.xml in UTF-8 format.
Follow this guide in order to save your file as a text file using the right encoding. than you can open it in eclipse or notepad to do the your copy paste
I just got my app strings translated to italian but having issues in displaying them on android device.
For example, one of the word is "velocità", on the device the last character à is shown as junk character.
Any pointers on how can I resolve it. The above word is present in the raw-it folder in a .txt file.
I assume you have the txt file not encoded as utf-8. Right click on the file in Eclipse and then properties. Set it to UTF-8. (You might need to copy the text into it again to make the characters appear ok).
UTF8 encoding supports foreign language characters. Try using UTF8 encoding. if that doesnt work then the problemmight be because of the font used.Good Luck.
I'm trying to add a Chinese version of my Strings.xml (into a project that already has an English and Spanish versions), and the app is simply crashing onlaunch, unable to even inflate the file. I'm assuming that there's some sort of encoding problem that I'm not taking into consideration, but I'm totally unfamiliar with what the requirements are to do this, so, am totally clueless as to what I should be doing to make this work.
I am setting my language to ch (perhaps this is not correct?) and the folder that the Strings.xml is in as values-ch. There is only one (test) string in the file which looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="q2_sp">請選擇您的語言。(英語/繁體中文)</string>
If I don't set the language to Chinese, it all continues to work fine (so the file is not corrupt) but when I set the language to chinese the app crashes on launch with a stack trace that complains about being unable to inflate the file. I can paste the stacktrace in if it's helpful, but am hoping that there's just something obvious I'm overlooking.
All help appreciated.
"ch" for Switzerland, for Chinese use "zh"
Is it possibly missing a byte order mark? A character user to indicate the whether the data stream is big endian or little endian - or possibly do the other localized data have a doctype indicating whether the data should be interpreted as utf 8 or 16? -- sorry - did not see you had the doctype there