How to use tools:locale for strings.xml files?

4k views Asked by At

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?

3

There are 3 answers

12
user2340612 On BEST ANSWER

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

6
Marco Acierno On

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">
0
Satyaki Mukherjee On

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.