IT story

Android Lint가 번역되지 않은 문자열에 대해 불평하지 않도록하십시오.

hot-time 2020. 7. 19. 09:15
반응형

Android Lint가 번역되지 않은 문자열에 대해 불평하지 않도록하십시오.


value-* 디렉토리 내 파일의 문자열 이 의도적으로 다른 언어로 번역되지 않도록 지정할 수 있습니까? 나는 모든 언어에 공통적 인 문자열을 가지고 있으며 번역이 필요하지 않으므로 디렉토리 unlocalized-strings.xml내에 파일을 만들었습니다 values. 문제를 확인하기 위해 Android Lint를 실행하면 일부 번역이 누락되었다는 것을 계속 말하고 있습니다. 전체 프로젝트 에서이 검사를 비활성화하려면 일부 XML 파일에서만 비활성화하고 싶습니다. 가능합니까?

"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.

지역화되지 않은 문자열 영역어떻게 정의 할 수 있습니까?


모든 파일을 무시하는 방법을 모르지만 다음을 사용하여 문자열별로 문자열을 수행 할 수 있습니다.

<string name="hello" translatable="false">hello</string>

다음과 같이 문자열 파일에서 네임 스페이스 ignore속성입니다 tools.

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

추가 build.gradle:

android {
     lintOptions {
        disable 'MissingTranslation'
    }
}

내가 아는 세 가지 방법이 있습니다.

값으로 수정 값을 적용하려면 정의 에서 속성 translatable="false"설정하십시오 <string>.

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

번역하지 말아야 할 리소스가 많은 경우 이름이 지정된 파일에 해당 리소스를 배치 할 수 donottranslate.xml있으며 lint는 모든 리소스를 번역 할 수없는 리소스로 간주합니다.

Hackers Keyboard 프로젝트 소스 를 탐색하는 동안 발견 한 또 다른 방법 : 리소스 파일에
접두사 donottranslate-추가 할 수 있습니다 . 앞의 예에서와 같이 lint는 모든 것을 번역 할 수없는 리소스로 간주합니다.
귀하의 경우에는, 당신은 대체 할 수 있습니다 unlocalized-strings.xmldonottranslate-strings.xml. 작동하는 것 같지만이 팁에 대한 문서를 찾지 못했습니다.

참조 : Android 도구 프로젝트 사이트 : 번역 할 수없는 문자열


그리고이 치명적인 Lint 오류를 비활성화하기위한 Android Studio 솔루션이 있습니다.

여기에 이미지 설명을 입력하십시오


보푸라기를 비활성화하는 대신 필요한 것은 속성으로 표시하는 것입니다.

translatable="false"

" donottranslate "로 시작하는 파일 이름을 가진 자원 파일을 작성하십시오 (예 : donottranslate.xml , donottranslate_urls.xml 등) lint는 누락 된 번역을 확인할 때 해당 문자열을 모두 무시합니다.


보풀이없는 번역을 확인하고 보푸라기를 돌리려면

"프로젝트 속성-> Android Lint 환경 설정-> MissingTranslation 선택-> 심각도를 무시하는 Swtich",

이 문제가 다른 사람들에게 도움이되기를 바랍니다.


다른 방법은 resValue또는을 사용하여 파일을 gradle 파일에 추가하는 것 buildConfigField입니다. 그런 것 :

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"
    }
}

사용법 :

// buildConfigField
BuildConfig.APP_NAME1

// resValue
getString(R.string.app_name2)

Android Studio에서 경고를 피하려면 환경 설정 ==> 검사를 열고 "불완전한 번역"을 선택 취소하십시오. 그러나 Gradle 빌드에는 영향을 미치지 않습니다.


"번역 편집기"도 있습니다 (string.xml "번역 편집기 열기"를 마우스 오른쪽 단추로 클릭).

그런 다음 문자열에서 '번역 할 수 없음'확인란을 선택하십시오.

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

참고 URL : https://stackoverflow.com/questions/12590739/avoid-android-lint-complains-about-not-translated-string

반응형