127

is it possible to specify that the strings in a file within the value-* directories are purposely not translated into other languages? I have a bunch of strings that are common for all the languages and need no translation, so I've created an unlocalized-strings.xml file within values directory.. Running Android Lint to check for problems it keeps saying that some translations are missing.. I do not want to disable this check on the whole project, I'd like to disable it only in some XML files.. is it possible?

"title_widget_updater_service" is not translated in de, en, en-rUS, it

Issue: Checks for incomplete translations where not all strings are translated
Id: MissingTranslation

If an application has more than one locale, then all the strings declared in one language     
should also be translated in all other languages.

By default this detector allows regions of a language to just provide a subset of the 
strings and fall back to the standard language strings. You can require all regions to 
provide a full translation by setting the environment variable 
ANDROID_LINT_COMPLETE_REGIONS.

How can defined this region of unlocalized strings?

Gianni Costanzi
  • 6,054
  • 11
  • 48
  • 74
  • [Error: “app_name” is not translated in af](https://stackoverflow.com/q/21118725/6521116) – LF00 Aug 09 '17 at 08:36

11 Answers11

238

It's the ignore attribute of the tools namespace in your strings file, as follows:

<?xml version="1.0" encoding="utf-8"?>
<resources
  xmlns:tools="http://schemas.android.com/tools"
  tools:ignore="MissingTranslation" >

  <!-- your strings here; no need now for the translatable attribute -->

</resources>
Adil Hussain
  • 30,049
  • 21
  • 112
  • 147
164

I don't know how to ignore all the file, but you can do it string by string using:

<string name="hello" translatable="false">hello</string>
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Luis
  • 11,978
  • 3
  • 27
  • 35
  • 1
    this gives 'non translatable resources should only be defined in the base values /folder. – fIwJlxSzApHEZIl Mar 05 '13 at 21:25
  • 3
    And that's correct. If you don't want a string to be translated, you should only define it in the "base values/folder", which means do not enter the string in the translated values/folder. – Luis Mar 05 '13 at 22:34
  • 1
    @CyrilLeroux answer is more comprehensive and should be marked as the correct one because it shows the option of putting all the non translatable strings in one file. – Yoel Gluschnaider Jan 27 '16 at 17:12
  • This works but I don't think is the best way to solve the problem by marking an actually translatable string "not translatable" just to suppress the error message. We just choose to not translate some strings for the time being. But that doesn't mean they are not translatable. – Zili FENG Sep 02 '16 at 06:53
  • I want to put string in only one language and that's German(de) language(not the default English) one. I put it there and when I try to release build it gave me error. What to do in this case? – Aanal Shah Nov 14 '18 at 07:13
154

Add to build.gradle:

android {
     lintOptions {
        disable 'MissingTranslation'
    }
}
Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
Giraffe Lion
  • 1,641
  • 1
  • 11
  • 6
  • 7
    The only workable solution for dealing with the auto-generated string resources.Thanks. – SqueezyMo Nov 27 '15 at 15:54
  • 7
    no it shouldn't, based on the question: "I do not want to disable this check on the whole project" – Yoel Gluschnaider Jan 27 '16 at 17:05
  • @Giraffe Lion you should post this as a different question and answer it yourself, Thanks for the solution, previously i had to disable it manually. – Diljeet Mar 09 '17 at 01:11
  • 1
    This disabled the whole check which should be avoided if possible. I cannot understand why it has this many votes. – tasomaniac Jan 22 '18 at 13:41
23

There are 3 ways that I know of :

To apply the modification value by value : Set the attribute translatable="false" on the <string> definition:

<string name="account_setup_imap" translatable="false">IMAP</string>

If you have a lot of resources that should not be translated, you can place them in a file named donottranslate.xml and lint will consider all of them non-translatable resources.

Another way I discovered while browsing Hackers Keyboard project sources:
You can add the prefix donottranslate- to your resource file. As in the previous example, lint will consider all of them non-translatable resources.
In your case, you can replace unlocalized-strings.xml by donottranslate-strings.xml. It seems to work, but I haven't found any documentation for this tip.

See: Android Tools Project Site: Non-translatable Strings

Cyril Leroux
  • 2,599
  • 1
  • 26
  • 25
  • Is it true that if we put our string in the file `donottranlate.xml`, we don't need to add the `translatable="false"` tag any more? – Yuchen Jun 23 '16 at 14:25
  • Yep. I use donottranslate-strings.xml files in all my project. Works fine. Try it, it's very usefull ! – Cyril Leroux Jun 23 '16 at 20:23
14

And here is a Android Studio solution for disabling this fatal Lint error:

enter image description here

Dzhuneyt
  • 8,437
  • 14
  • 64
  • 118
  • 2
    It may an annoying error, but it could save you when you accidentally forget to translate a new string to one of your app languages. – Elad Nava Oct 05 '15 at 16:48
2

I think that what you need instead of disabling lint is to mark them with attribute

translatable="false"
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
2

Create a resource file with a file name starting with "donottranslate" (e.g. donottranslate.xml, donottranslate_urls.xml, etc), and lint will ignore its strings altogether when checking for missing translations.

Kai
  • 15,284
  • 6
  • 51
  • 82
1

If you want to turn of the lint checking on missing translation, you may go

"Project Properties -> Android Lint Preferences -> Select MissingTranslation -> Swtich To Ignore In Severity",

hopes this helps others cause i just encounter this problem :)

hctang
  • 41
  • 4
1

Another way to do that is add your string to gradle file, using resValue or buildConfigField. Something like that:

buildTypes {
    debug {
        buildConfigField "string", "app_name1", "App Name"
        resValue "string", "app_name2", "App Name"
    }
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        buildConfigField "string", "app_name1", "App Name"
        resValue "string", "app_name2", "App Name"
    }
}

Usages:

// buildConfigField
BuildConfig.APP_NAME1

// resValue
getString(R.string.app_name2)
heloisasim
  • 4,956
  • 2
  • 27
  • 36
0

To avoid warnings in Android Studio, open Preferences ==> Inspections, uncheck "Incomplete translations". But it won't affect Gradle build.

Kof
  • 23,893
  • 9
  • 56
  • 81
0

There is also the "Translation editor" (right click on string.xml "Open Translation Editor").

Then check the 'Untranslatable' box on a string.

https://developer.android.com/studio/write/translations-editor

user1010160
  • 445
  • 3
  • 9