1

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?

musooff
  • 6,412
  • 3
  • 36
  • 65
android developer
  • 114,585
  • 152
  • 739
  • 1,270

3 Answers3

3

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

user2340612
  • 10,053
  • 4
  • 41
  • 66
  • I don't get it, so how do i set Lint to warn me only about specific languages? and why do i need this attribute anyway? – android developer Jan 01 '14 at 13:13
  • With this optional attribute you can specify what is the language of the resource file into "values" folder. Actually Lint checks all the languages that exists in your project (and linked libraries). So if your project has "values", "values-iw" and "values-he" folders then Lint should warn only about he/iw missing translations. But if you add ActionBarSherlock library (which includes many other translations, such as "de", "it", ...), then Lint will warn you about missing strings in those languages – user2340612 Jan 02 '14 at 17:34
  • So because of ABS, it will keep warning me of other languages? Any way to avoid this? Also, you say that the attribute is intended only for the "values" folder and you can add there only a single locale? so it's just an equivalent to putting the strings files into the "values-en" ? – android developer Jan 02 '14 at 18:09
  • Yes, because of ABS it will complain about all other languages. You can avoid that by removing ABS library, run lint check, re-add ABS. Well tools:locale="en" is not equivalent to "values-en" because the former specifies the language for the spell checker, so android will use those strings for all locales (exluding hebrew, because of the "values-he", "values-iw" folders), while the latter will be used only if the device locale is "english". – user2340612 Jan 03 '14 at 18:47
  • About ABS, I can just make Lint to work on the current project, but that's annoying since I would have to do it for each project. I don't understand the part about the locale attribute. you mean it's just for spell checking , or does it also have a role with Lint? what happens on a device that doesn't have an english locale and I only have "values-en" (and others) but not "values" ? or devices that don't fit any locale bucket in this case? – android developer Jan 03 '14 at 23:32
  • from Android docs:`Whenever the application runs in a locale for which you have not provided locale-specific text, Android will load the default strings from res/values/strings.xml. If this default file is absent, or if it is missing a string that your application needs, then your application will not run and will show an error.` So the "values" folder is quite important, since android will pick strings from there if there is no translation available for the current locale! – user2340612 Jan 04 '14 at 16:33
  • Oh, I see. So putting strings into the "values" folder is important. But does the special attribute used for spellcheck only? it has nothing to do with Lint? – android developer Jan 04 '14 at 16:45
  • yes, `Lint will use the locale information to for example pick the right typo dictionary when looking for misspellings in your default strings` ; – user2340612 Jan 04 '14 at 16:52
  • Lint is the one responsible for spell checks? doesn't eclipse already has this built in? – android developer Jan 04 '14 at 16:54
  • yes, lint does some spell checks (look [here](http://tools.android.com/tips/lint-checks) for a complete list of checks, you'll find "typos" paragraph).. i think this is done because you can write android apps without an IDE, so you might not have other spell checkers – user2340612 Jan 04 '14 at 17:22
  • nice. weird that i didn't notice Lint ever warning me about typos. but i still don't understand something : Does Lint use the special attribute for the spell check only, or does it use it for anything else? – android developer Jan 04 '14 at 20:10
  • OK, I've finally started using it and I still don't get it. Why and when should I use this attribute? If I use English on the "res/values" folder, should I use it? When I use it, I get a lot of warnings, for example ""search" is translated here but not found in default locale . it even happens when I put the file into "res/values-en" folder. – android developer Mar 28 '14 at 13:53
2

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">
Marco Acierno
  • 14,682
  • 8
  • 43
  • 53
  • so i got it all wrong ? so you mean i should put just what you've written in the "values" folder? then how do i tell Lint to only warn me about specific languages? also, – android developer Dec 28 '13 at 12:34
  • You should use tools:locale only to specify what is the language of the default values folder (Go to string.xml and in the root element add `tools:locale="en"`). Other values folder already have the locale in the folder name. (values-he) But anyway, as far as i know english is already the default language for the values folder. Use tools:locale only if you use a different language in the default strings (values/strings.xml) – Marco Acierno Dec 28 '13 at 12:56
  • @androiddeveloper do you include any external project/lib, like Google play store project? – user2340612 Dec 28 '13 at 13:03
  • you mean external android projects? if so, yes. i usually use the actionBarSherlock library, for example. – android developer Dec 28 '13 at 13:06
  • so probably you get many lint errors about translations because that external library specifies many translations, while your app doesn't. I think that there is no way to fix this problem right now. Someone suggests to remove external libraries, run lint check to get missing translations (only for the languages that you specify) and re-add external libraries. – user2340612 Dec 28 '13 at 13:21
  • You can choose to use Lint on a specific project. no need to change the hierarchy of your projects... – android developer Jan 01 '14 at 12:56
0

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.

Satyaki Mukherjee
  • 2,857
  • 1
  • 22
  • 26