2022년 10월 10일 월요일

국제화에 필요없는 리소스는 translatable="false"

국제화에 필요없는 리소스는 translatable="false"

국제화에 필요없는 리소스는 translatable=“false”

국제화에 필요없는 리소스는 translatable=“false” 를 추가하여 빌드오류가 안나도록 할수 있다. \

<resources> \
   <string name="app_name" translatable="false">EasyApp&lt;/string> \
    <string name="my_string">me&lt;/string>

</resources>

언어변경시에 리소스를 다시 읽기 위해서 처리하는 예제

앱에서 언어변경시 리소스를 다시 읽어야 되는데 ComtenxtThemeWrapper를 통해 설정값을 다시 읽으면된다.
Context의 확장함수로 만들거나, 모든 액티비티에서 사용할수 있도록 BaseActivity 를 만들어서 상속받아 쓰는 방법도 있다.

open class BaseActivity : AppCompatActivity() {  
  
    companion object {  
        var dLocale: Locale? = null  
  }  
  
    init {  
        updateConfig(this)  
    }  
  
    fun updateConfig(wrapper: ContextThemeWrapper) {  
        if(dLocale == Locale("") ) // Do nothing if dLocale is null  
  return  
  
  Locale.setDefault(dLocale)  
        val configuration = Configuration()  
        configuration.let {  
 it.setLocale(dLocale)  
            wrapper.applyOverrideConfiguration(it)  
        }  
  }  
}

좀더 자세한 예제는 https://medium.com/swlh/android-app-specific-language-change-programmatically-using-kotlin-d650a5392220

0 comments:

댓글 쓰기