Search code examples
androidandroid-studiocode-inspection

Android Studio error message I18n


I got an error message that says:

[I18N] Hardcoded string "Today - Sunny - 78/67", should use @string resource.

How can this error be resolved?

The line of code is: android:text="Today - Sunny - 78/67"


Solution

  • i18n is an abbreviation for internationalization. Android Studio is just giving you a hint that the way you are setting the text won't allow you to easily translate it.

    Instead you should put your string in a strings.xml file within the res/values folder:

    <resources>
      <string name="my_string">Today - Sunny - 78/67</string>
    </resources>
    

    You then reference that string on your TextView like this:

    android:text="@string/my_string"
    

    This would allow you to make another file for spanish strings, res/values-es/strings.xml that you could add a translation to:

    <resources>
      <string name="my_string">Hoy - Soleado - 78/67</string>
    </resources>
    

    And then that string will automatically get picked for your TextView if the user's locale language is Spanish.