Android Lint: how to ignore missing translation warnings in a specific file

Is it possible to translate some strings, but not all, in a separate resource file without Lint complaining about MissingTranslation?

For example: my app’s strings are all in res/values/strings.xml. One of the strings is

  • Change icon color of FAB based on state w/ compat libs
  • Android: MediaPlayer gapless or seamless Video Playing
  • Cannot install signed apk to device manually, got error “App not installed”
  • What are the differences between T-Mobile G1 (branded HTC Dream) and Google's ADP1 (device for developers)?
  • Uncaught ReferenceError: Media is not defined
  • How to finish multiple activities on a button click?
  • <string name="postal_code">Postal Code</string>

    Since “postal code” is usually called “zip code” in the US, I want to add another resource res/values-en-rUS/strings.xml with contents:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="postal_code">Zip Code</string>
    </resources>
    

    However, Lint complains about other strings in values/strings.xml but not in values-en-rUS/strings.xml

    I realize you can suppress the warnings by specifying tools:ignore in values/strings.xml. But this is undesirable because the Lint warning is actually useful when translating to another language.

    Instead, is it possible to suppress the warning in the values-en-rUS/strings.xml file, as in, telling Lint not to use that file as criteria when looking for missing translations?

    Related posts:

    Heads-up Notification - Android Lollipop
    no resource found @integer/google_play_services_version whats this?
    Can&#039;t get backspace to work in codemirror, under Phonegap on Android 4.x?
    Installing Android Studio, does not point to a valid JVM installation error
    DSR is on. Don&#039;t send DTR on Android
    How to use OSM map in an android application.? Is there any tutorial to learn about using OSM in and...
  • How to center multiple Views together using ConstaintLayout?
  • First frame of the background video doesn't show on Android
  • fab.show() not animated first time after initializing new activity
  • Retrofit connection failure returns RetrofitError.response as null
  • Custom gallery view in android
  • Android SeekBarChangeListener and TouchListener No Events
  • 5 Solutions collect form web for “Android Lint: how to ignore missing translation warnings in a specific file”

    A nice way to disable MissingTranslations check is to add the option in module specific build.gradle file .

    android {
    
     lintOptions{
            disable 'MissingTranslation'
        }
    //other build tags
    }
    

    If the strings are not present in locale specific Strings file, it will take the strings from the default file which generally is Strings.xml.

    I found a better solution according to this answer: https://stackoverflow.com/a/13797364/190309

    Just add ignore="MissingTranslation" to your string.xml, for example:

    <?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>
    

    This seems to not answered yet, so I show you one solution:

    In your DEFAULT xml file, you can define strings, that don’t need translations like following:

    <string name="developer" translatable="false">Developer Name</string>
    

    This string does not need to be translated and lint will not complain about it either…

    Lint has specific support for only overriding some elements in region-specific resources files (e.g., en-rUS overriding en). If the region is for the default locale, you have to let it know what language your default strings are by specifying the locale in values/strings.xml:

    <resources xmlns:tools="http://schemas.android.com/tools" tools:locale="en">
    

    From lint:

    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 tell lint (and other tools) which language is the default language
    in your res/values/ folder by specifying tools:locale=”languageCode” for
    the root element in your resource file. (The tools prefix
    refers to the namespace declaration http://schemas.android.com/tools.)

    Add the locale specification to your default language file, and you shouldn’t get that error for en-rUS, but will still be informed of any other missing translations.

    If you are using Eclipse, please look at the toolbar buttons of the Lint warnings view. One of them is called “Ignore in file”. This should help, but only if Lint assigns the error to your “US” file. That button simply modifies the lint.xml file in your project, so you can investigate (and undo) that easily.

    More details about that file specific suppression are at http://tools.android.com/tips/lint/suppressing-lint-warnings

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.