On Android, I would like to suppress lint on a specific string value or specific line on a string.xml or other resources files.
<string name="suppress_lint_string">Suppress this String</string>
<string name="dont_suppress_lint_string">Don\'t Suppress this String</string>
I would like to perform specific lint suppressing on specific strings and specific parts of layouts for examples like missing translations for specific strings that doesn't really matter between languages.
If you want to suppress specific rules in specific strings without suppressing the whole file, you can use annotations.
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--suppress MissingTranslation -->
<string name="suppress_lint_string">ignore my translation</string>
...
</resources>
You can substitute MissingTranslation with any other lint rule.
http://tools.android.com/tips/lint/suppressing-lint-warnings
Related
I translated my application in the Japanese language. I added regularly the xml file, inside the folder values-ja-rJP .
Android studio is regularly set in UTF-8, but when I start my application on my device, the application uses the default language. I need to do something? the problem occurs only with the Japanese language. Thank you
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="action_settings">設定</string>
<string name="new_field">新規分野</string>
...
...
</resources>
Is there a way how to add comment/description/documentation to android resource reference? The only way I know is to use standart XML comment. Which is not ideal obviously.
Something like special attribute or special javadoc pre-element
<resources>
<string documentation="Some useful information what does this resource means..." name="KEY" translatable="false">value</string>
</resources>
<resources>
<documentation forName="KEY">Some useful information what does this resource means...</documentation>
<string name="KEY" translatable="false">value</string>
</resources>
Not ideal but currently functional way:
<resources>
<!-- Some useful information about what this resource means... -->
<string name="KEY" translatable="false">value</string>
</resources>
The following format allows for a file header (using XML documentation comments), as well as as an individual comment (a documentation attribute) that goes along with each resource entry. I haven't had the compiler complain that a specific namespace (other than xmlns:tools) that contains documentation is required.
<?xml version="1.0" encoding="utf-8"?>
<!--=============================================================================================
My File description here
==============================================================================================-->
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="Application_Name" documentation="Name of the application. Used as Activity Name as the title, and appears in About box">FantasticApp</string>
</resources>
I'm going to translate my application strings.xml file. Which is default language of strings.xml file? because now i need to support italian (the language with i've write strings.xml for now) and english. Should i use string.xml for english and create
res/values-it/
folder for italian, and translate "default" strings.xml in english?
strings.xml is the default and will be used if there is no country specific file like res/values-it/strings.xml or res/values-fr/strings.xml. Read more about Localizing with Resources.
I would personally use strings.xml with english translations as a fallback as you already suggested.
Take a look here; as stated:
Create Locale Directories and String Files
To add support for more languages, create additional values directories inside res/ that include a hyphen and the ISO country code at the end of the directory name. For example, values-es/ is the directory containing simple resourcess for the Locales with the language code "es". Android loads the appropriate resources according to the locale settings of the device at run time.
Once you’ve decided on the languages you will support, create the resource subdirectories and string resource files. For example:
MyProject/ res/ values/ strings.xml values-es/ strings.xml values-it/ strings.xml
Add the string values for each locale into the appropriate file.
At runtime, the Android system uses the appropriate set of string resources based on the locale currently set for the user's device.
For example, the following are some different string resource files for different languages.
English (default locale), /values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">My Application</string>
<string name="hello_world">Hello World!</string>
</resources>
Italian, /values-it/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">la mia domanda </string>
<string name="hello_world">ciao mondo!</string>
</resources>
Note:You can use the locale qualifier (or any configuration qualifer) on any resource type, such as if you want to provide localized versions of your bitmap drawable. For more information, see Localization.
If you want to have only one strings.xml file and you would like to localize to Italian, all you need to do is add the following line to your strings.xml file.
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="it">
locale="it" -> Italian, locale="fr" -> French, etc.
Is there a way to add localization setting in my app? I'm going to add a preference/setting in my app and there is a localization option. So the user can change the language I have provided from the values string.
I was googling around but found nothing. Wondering you guys can help me, and give example or link to the tutorial.
You don't need to provide a setting for that, Android will do that for you. You just have to provide the translations for the languages you want to support.
You can do this for French for example by creating a folder named res/values-fr in your resources folder and putting your translations in there.
so in the res/values folder you would have a strings.xml file :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="q_map">Map</string>
</resources>
and in the res/values-fr you woud have another string.xml file :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="q_map">Carte</string>
</resources>
Your app will use the translation that best matches the language that the user has selected on their device.
I'm making an android app and since I've just started I want to try get the most organised code/resources. In my strings.xml file so far I have this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">GameController</string>
<string name="stop">Stop</string>
<string name="start">Start</string>
<string name="preferences">Preferences</string>
<string name="back">Back</string>
</resources>
All of the strings except app_name are used in an options menu. But since I will be adding much more strings I was thinking that it might be better to do something like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">GameController</string>
<string name="menu_stop">Stop</string>
<string name="menu_start">Start</string>
<string name="menu_preferences">Preferences</string>
<string name="menu_back">Back</string>
</resources>
Is it the best way or should I use another system?
It depends on where the strings will be used. If "stop" will never be used anywhere but in a menu, calling it "menu_stop" is a good idea. If it'll be used all over the place then it should just be called "stop".
Also, XML comments are very useful for organizing resources.
<resources>
<string name="app_name">GameController</string>
<!-- Menu Strings -->
<string name="menu_stop">Stop</string>
<string name="menu_start">Start</string>
<string name="menu_preferences">Preferences</string>
<string name="menu_back">Back</string>
</resources>
Finally, if you find you have tons and tons of string resources you may want to go so far as to separate them into different xml files: menu_strings.xml, dialog_strings.xml, etc.
menu_strings.xml
<resources>
<!-- Menu Strings -->
<string name="menu_stop">Stop</string>
<string name="menu_start">Start</string>
<string name="menu_preferences">Preferences</string>
<string name="menu_back">Back</string>
</resources>
dialog_strings.xml
<resources>
<string name="dialog_cancel_yes">Yes, cancel.</string>
<string name="dialog_cancel_no">No, do not cancel.</string>
</resources>
This is kind of a subjective question, really. You should use whatever you find easier to handle. I certainly do the second type of naming when I'm using layouts and drawables (e.g. button_x, ninepatch_x, icon_x, etc.), just because it keeps them next to each other, and is easier to narrow down quickly with Content Assist. In XML, you can use comments to group them together, and add white space, just anything that makes it easier for you to find what you need, and quickly.