How translate App Label

Discussion in 'Android Questions' started by cb56, Dec 31, 2012.

  1. cb56

    cb56 Member Licensed User

    Hi,
    it' possible with b4a translate the App label (the label under the Icon in App drawer) based on language settings or by code?

    thanks
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Android doesn't allow you to dynamically set the app label.
     
  3. cb56

    cb56 Member Licensed User

    I did some research and found out how to change the label of the application when you change the language in the device settings.

    In the manifest, insert the line:

    Code:
    SetActivityAttribute("main", android:label"@string/app_name")

    SetActivityAttribute(
    "main", android:configChanges, "locale")
    Manifest:

    Code:
    'This code will be applied to the manifest file during compilation.
    'You do not need to modify it in most cases.
    'See this link for for more information: http://www.basic4ppc.com/forum/showthread.php?p=78136
    AddManifestText(
    <uses-sdk android:minSdkVersion=
    "4" android:targetSdkVersion="14"/>
    <supports-screens android:largeScreens=
    "true" 
        android:normalScreens=
    "true" 
        android:smallScreens=
    "true" 
        android:anyDensity=
    "true"/>)
    SetApplicationAttribute(android:icon, 
    "@drawable/icon")
    SetActivityAttribute(
    "main", android:label"@string/app_name")
    SetActivityAttribute(
    "main", android:configChanges, "locale")
    'End of default text.
    Then, in folder "Objects\res" create folders for languages, like this:

    "values-de"
    "values-en"
    "values-fr"
    "values-it"
    "values-nl"

    etc...

    if you do not expect some languages, for default settings, insert a folder named "values".

    In each folder insert an xml file, named "strings.xml" with this content:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
       <
    string name="app_name">Label to display</string>
    </resources>
    Change the string "Label to display" with the translated one.

    Make all folder and file Read Only because b4a will delete!

    cb56
     
  4. lock255

    lock255 Well-Known Member Licensed User

    E 'can also translate the text of a button, edittex, listview etc?
    If the answer is yes, please make me an example for these three?
     
  5. cb56

    cb56 Member Licensed User

  6. lock255

    lock255 Well-Known Member Licensed User

  7. corwin42

    corwin42 Expert Licensed User

    One short note. You don't need to use
    Code:
    SetActivityAttribute("main", android:label"@string/app_name")
    You can use the application attribute:

    Code:
    #ApplicationLabel: @string/app_name
     
    Informatix and asales like this.
  8. enrico

    enrico Active Member Licensed User

    I get this error :

    Parsing code. 0.04
    Compiling code. 0.05
    Compiling layouts code. 0.00
    Generating R file. Error
    res\values-es\strings.xml:3: error: Error parsing XML: not well-formed (invalid token)
    res\values-fr\strings.xml:3: error: Error parsing XML: not well-formed (invalid token)

    This is my Manifest :

    Code:
    AddManifestText(
    <uses-sdk android:minSdkVersion=
    "4"/>
    <supports-screens android:largeScreens=
    "true"
        android:normalScreens=
    "true"
        android:smallScreens=
    "true"
        android:anyDensity=
    "true"/>)
    SetApplicationAttribute(android:icon, 
    "@drawable/icon")
    SetApplicationAttribute(android:
    label"$LABEL$")
    SetActivityAttribute(
    "Main", android:label"@string/app_name")
    SetActivityAttribute(
    "Main", android:configChanges, "locale")
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    The problem is in the strings xml files (line 3).
     
  10. enrico

    enrico Active Member Licensed User

    The problem were characters like ñ û.
    Can't I use them ? Changing UTF ?
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Can you upload one of these files?
     
  12. enrico

    enrico Active Member Licensed User

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
      <
    string name="app_name" formatted="false">ñññ</string>
    </resources>
    Same thing without formatted="false"
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    There shouldn't be a problem as long as the file is actually saved as a utf 8 file.
     
  14. enrico

    enrico Active Member Licensed User

    Unfortunately my problem still remains.
    This time I will bypass it not using those characters, but I would like to understand how to solve it.
     
  15. corwin42

    corwin42 Expert Licensed User

    You should use unicode characters. These strange codes beginning with \u

    For a converter look here.
     
  16. enrico

    enrico Active Member Licensed User

    Oh, Yes. This appears to be the solution.
    Thank You.
     
  17. Jack Cole

    Jack Cole Active Member Licensed User

    Using either method (specifying through #ApplicationLabel: @string/app_name or through the manifest file), I get the following error when trying to compile:

    Under res/xml/values/strings.xml I have:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
       <
    string name="app_name">Test App</string>
    </resources>
    I have also tried naming the folder values-en.

    An example project is attached. Any ideas about what I'm doing wrong?
     

    Attached Files:

  18. Erel

    Erel Administrator Staff Member Licensed User

    There are several mistakes in this project.

    With v5.80 there is a simpler way to use resources. Delete the xml files and the custom build action. Use this manifest editor code instead:
    Code:
    AddManifestText(
    <uses-sdk android:minSdkVersion=
    "5" android:targetSdkVersion="19"/>
    <supports-screens android:largeScreens=
    "true"
      android:normalScreens=
    "true"
      android:smallScreens=
    "true"
      android:anyDensity=
    "true"/>)
    SetApplicationAttribute(android:icon, 
    "@drawable/icon")
    SetApplicationAttribute(android:
    label"@string/app_name")
    'End of default text.

    CreateResource(values, strings.xml,
    <resources>
      <
    string name="app_name">Test App</string>
    </resources>
    )
    You can create multiple resources if you need more languages.
     
    fredo and Jack Cole like this.
  19. Jack Cole

    Jack Cole Active Member Licensed User

    Thanks Erel. I had not thought to use that new feature. Unfortunately though, it still is not working. Using the above manifest code in a brand new project gives the results of the following. The #ApplicationLabel attribute somehow overrides what is specified in the manifest editor above. If I delete the #ApplicationLabel line in the project, the app label changes back the B4A Example.
     
  20. Informatix

    Informatix Expert Licensed User

    Is your #ApplicationLabel set to @string/app_name ?
     
    Jack Cole likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice