Here's one that's driving me crazy:
I have recently started looking into Appcelerator Titanium. I have built a few small apps both with a normal project and using Alloy so I understand the basics at least.
One thing I just cannot get working is the i18n folder/files.
Here is what ive done:
- Create a "Default Project"
- add folder to root directory "i18n"
- add "en" and "es" folder to "i18n"
- add "strings.xml" to both those new folders.
- added:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Welcome TEST</string>
</resources>
to both the strings.xml, except in the es strings I put "ES Welcome TEST".
- In Resources -> app.js I changed "I am Window 1" to L('welcome_message')
- Ran the application
Both the normal and alloy versions just show a blank screen. I would like to get my alloy app working the most but from what I understand the localization code should work the same in both apps. In alloy I may just have to put it in the style.
Any pointers would be great! I have looked at other post claiming its not working but all of them were either syntax errors or just set it up wrong. I have copied their code and have the exact same issue with it not working so I have a feeling im missing a newbie step.
-- Here are some screenshots, I just created a brand new regular(not alloy) project, added the code above and try to use L('welcome_message') to no luck. I tried installing everything on a new PC to make sure I wasn't messing anything up on my main computer.
Heres the answer:
https://wiki.appcelerator.org/display/guides/Internationalization
Ends up by default your manifest file is not setup by default to allow localization UNLESS you choose a tabbed project.
Kinda silly if you ask me.
For the topic poster:
My new string.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Don't Help Austin</string>
<string name="user_agent_message">user agent set to</string>
<string name="format_test">Your name is %s</string>
<string name="base_ui_title">Base UI</string>
<string name="controls_win_title">Controls</string>
<string name="phone_win_title">Phone</string>
<string name="platform_win_title">Platform</string>
<string name="mashups_win_title">Mashups</string>
<string name="ordered">Hi %1$s, my name is %2$s</string>
</resources>
Screenshot of my non-Alloy experiment:
For those looking to answer the question in the topic, this is a possible answer below.
My i18n folder is on the same hierarchy level as app and plugins, so mine isn't inside the app folder like the rest of the Alloy resources.
index.xml
<Alloy>
<Window class="container">
<Label id="label" onClick="doClick"></Label>
</Window>
</Alloy>
index.tss
".container": {
backgroundColor:"white"
},
"Label": {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000",
text: L("welcome_message")
}
strings.xml
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Welcome to Kitchen Sink for Titanium</string>
<string name="user_agent_message">user agent set to</string>
<string name="format_test">Your name is %s</string>
<string name="base_ui_title">Base UI</string>
<string name="controls_win_title">Controls</string>
<string name="phone_win_title">Phone</string>
<string name="platform_win_title">Platform</string>
<string name="mashups_win_title">Mashups</string>
<string name="ordered">Hi %1$s, my name is %2$s</string>
</resources>
When I placed the L("welcome_message") inside the index.xml, it didn't work.
Related
I want to use a github library Android about page in Greek language.
As i can see the library support Greek. Do i need to set localization in my project? (It will be only in Greek language).
I tried adding values-el folder with strings.xml in Greek inside , and add the Greek strings in my values-->strings.xml with no luck.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="about_contact_us">Επικοινωνήστε μαζί μας</string>
<string name="about_instagram">Ακολουθήστε μας στο Instagram</string>
<string name="about_facebook">Κάντε like στην σελίδα μας στο Facebook</string>
<string name="about_play_store">Αξιολογήστε μας στο Play Store</string>
<string name="about_youtube">Παρακολουθήστε μας στο YouTube</string>
<string name="about_twitter">Ακολουθήστε μας στο Twitter</string>
<string name="about_github">Καντε μας fork στο Github</string>
<string name="about_website">Επισκεφθείτε την ιστοσελίδα μας</string>
</resources>
If i need to set localization, whats the easiest way as its the only thing i need translated?
Do i need to set localization in my project ...
No, you don't.
Greek localized strings just will work fine, you should see them without any additional movements if your device's system language is Greek.
I'm working with android studio to develop Android app. I'm working on the creation of a template to use in my applications. I have read the Android IDE Template Format specification and so i start my personal template starting from Dummy template.
I have a .ftl file with the following line of code:
<applicationGestureListenerClazz>${projectPackageName}.listeners.${projectShortName}GestureListener</applicationGestureListenerClazz>
When i execute the template i obtain the following line:
<applicationGestureListenerClazz>org.abubu.dummy.listeners.DummyGestureListener
</applicationGestureListenerClazz>
The variables are correctly defined (in other file they work fine). I don't known why.. it add a CRLF after this line.
Anybody has analogue problem?
UPDATE
I discover that the problem is linked to extension of output file. For example. I have a file **license_key_strings.txt.ftl* that contains:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- public key di ${projectPackageName}.key-->
<string name="publicKey">${licenseKey}</string>
</resources>
<!-- fine -->
If i use it to create a xml file
<instantiate from="root/key/src/main/res/values/license_key_strings.txt.ftl" to="${keyBaseDir}/src/main/res/values/license_key_strings.xml"/>
I obtain this file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- public key di org.dummy.key-->
<string name="publicKey">
MIIBIjANBgkqhkiG9w0BAQ
</string>
</resources>
But the output filename ends with .txt
<instantiate from="root/key/src/main/res/values/license_key_strings.txt.ftl" to="${keyBaseDir}/src/main/res/values/license_key_strings.txt"/>
The final output become:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- public key di org.dummy.key-->
<string name="publicKey">MIIBIjANBgkqhkiG9w0BAQ</string>
</resources>
<!-- fine -->
I'm working with Android Studio 1.4
I have ios string file that i want to convert into the Android xml file:
This is the ios string file which i have want to convert into the Android xml file:
/*
Localizable.strings
SaiÌda da Escola
Created by farhan shah on 11/12/2013.
Copyright (c) 2013 whizpool. All rights reserved.
*/
"settings_button" = "Settings";
"location" = "Destiny";
"Register_button" = "Register";
"logout" = "Log Out";
"login_button" = "Login";
"ok" = "Ok";
"yes" = "Yes";
"no" = "No";
the result should be like this like Android xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--
Localizable.strings
SaiÌda da Escola
Created by farhan shah on 11/12/2013.
Copyright (c) 2013 whizpool. All rights reserved.
-->
<string name="settings_button">Settings</string>
<string name="location">Destiny</string>
<string name="register_button">Register</string>
<string name="logout">Log Out</string>
<string name="login_button">Login</string>
<string name="ok">Ok</string>
<string name="yes">Yes</string>
<string name="no">No</string>
</resources>
any help,idea and sample code will be highly appreciated,Thanks alot in advance.
You can take a look at the JavaScript code in the page below, and you could do something similar in Java. It uses regular expressions to parse the input files.
http://members.home.nl/bas.de.reuver/files/stringsconvert.html
You cannot convert this "programatically" using Android code, because those strings need to be available in your project's resources before compilation, of course.
You could use a simple bash script, like:
echo '<?xml version="1.0" encoding="utf-8"?>'
echo '<resources>'
while read line ; do
tag=$(echo $line | cut -d'"' -f2)
trad=$(echo $line | cut -d'"' -f4)
echo " <string name=\"$tag\">$trad</string>"
done < <(cat Localizable.strings | egrep '^".+"\s?=\s?.+$')
echo '</resources>'
That outputs:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="settings_button">Settings</string>
<string name="location">Destiny</string>
<string name="Register_button">Register</string>
<string name="logout">Log Out</string>
<string name="login_button">Login</string>
<string name="ok">Ok</string>
<string name="yes">Yes</string>
<string name="no">No</string>
</resources>
Use it like:
$ bash strings.bash > strings.xml
Note: Everything there is just an example I coded in a minute, adapt as you wish.
Android
I got the following code in an xml file in the res folder.
<?xml version="1.0" encoding="utf-8"?>
<designs>
<design name="2Parts">
<module id="0" posY="0" posX="0" height="0.5" width="1" capHeight="0.2"></module>
<module id="1" posY="0.5" posX="0" height="0.66" width="1" capHeight="0.2"></module>
</design>
Instead of using height="0.5" I'd like to have a variable from the Strings like height="#string/height_one" . But somehow I can't use the #string function.
Is that possible?
Is there an easy way to calculate with the strings in other files?
For an example :
height="#string/height_one * 0.5" ?
Looking forward to your answers
I must make a few translations for my app.
But when I compile my app, console write:
[2012-11-24 15:31:43 - com.ddm.ctimer.MainForm] W/ResourceType( 4892): Bad XML block: header size 297 or total size 0 is larger than data size 0
[2012-11-24 15:31:43 - com.ddm.ctimer.MainForm] C:\Users\Roman\Desktop\NewTimer\NewTimer\res\values-fr\strings.xml:6: error: Found text "
[2012-11-24 15:31:43 - com.ddm.ctimer.MainForm] В В В В " where item tag is expected
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CTimer</string>
<!--RUS strings-->
<!--MainForm-->
<string name="main_form_sec">Chronomètre</string>
<string name="main_form_tim"> Minuterie </string>
<string name="main_form_set"> Paramètres </string>
<string name="main_form_bg">#000000</string>
<!--Menu-->
<string name="menu_about">À propos du programme</string>
<string name="menu_buy">Supprimer les annonces</string>
<!--Preferences(Settings)-->
Most probably you have a problem with the encoding, resource files are supposed to be encoded in UTF-8.
Please, try to replace "Chronomètre" with something in plain English and see if your error disappears or moves to the next "translated" line.
It's better to use colors.xml for colors:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="main_form_bg">#000000</color>
</resources>