Avoid Android Lint complains about not-translated string

后端 未结 11 1593
轻奢々
轻奢々 2020-12-02 13:06

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

相关标签:
11条回答
  • 2020-12-02 13:08

    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 :)

    0 讨论(0)
  • 2020-12-02 13:09

    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

    0 讨论(0)
  • 2020-12-02 13:13

    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.

    0 讨论(0)
  • 2020-12-02 13:14

    Add to build.gradle:

    android {
         lintOptions {
            disable 'MissingTranslation'
        }
    }
    
    0 讨论(0)
  • 2020-12-02 13:16

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

    translatable="false"
    
    0 讨论(0)
  • 2020-12-02 13:16

    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)
    
    0 讨论(0)
提交回复
热议问题