I'm trying to read from the API's i've created using Kimono. However, when i print it in my console it seems like it can't read Mandarin Chinese in my xcode?
Am I missing something here?
Here's my code:
let myContentsToBeScanned = NSURL(string: "https://www.kimonolabs.com/api/7ant5tkm?apikey=jlZUlWROWVJjPFrVbCwdmmcIaTWO6ISI")
let myDataToBeRead = NSData(contentsOfURL: myContentsToBeScanned!)
do {
let myContentsFromJSON = try NSJSONSerialization.JSONObjectWithData(myDataToBeRead!, options: [])
print(myContentsFromJSON)
} catch let err as NSError {
print("nil")
}
I am getting the output:
results = {
collection1 = (
{
articleSum = "\U611f\U53d7\U842c\U8056\U7bc0\U8a6d\U8b4e\U602a\U8a95\U53c8\U6b61\U6a02\U7121\U6bd4\U7684\U6c23\U6c1b\Uff0c\U5c31\U4f86 Garena \U96fb\U7af6\U9928\U5427\Uff01";
articleTitles = "\U3010\U6d3b\U52d5\U3011\U5e7d\U6ba4\U65b0\U5a18\U904a\U8569\U4e2d\Uff0c\U842c\U8056\U7bc0\U4f86\U96fb\U7af6\U9928\U300c\U9b3c\U6df7\U300d\U5427\Uff01";
Thanks for your help
It's simply that the default Xcode font, Menlo, does not support Chinese character. The fact that the Unicode code points are print means your characters are there.
You can verify this by opening the Font Book app, search Menlo, then Cmd + I to see the Font Info. Menlo supports the following languages:
Language: Afrikaans, Albanian, Azerbaijani, Basque, Belarusian, Bulgarian, Catalan, Cornish, Croatian, Czech, Danish, Dutch, English, Esperanto, Estonian, Faroese, Finnish, French, Galician, German, Greek, Hausa, Hawaiian, Hungarian, Icelandic, Indonesian, Irish, Italian, Kalaallisut, Kazakh, Latvian, Lithuanian, Macedonian, Malay, Maltese, Manx, Norwegian Bokmål, Norwegian Nynorsk, Oromo, Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovenian, Somali, Spanish, Swahili, Swedish, Swiss German, Turkish, Ukrainian, Uzbek, Welsh, Zulu
You can change Xcode to use a monospace font that does support Chinese, like MingLiU or SimHei. The easiest way to find out which font is available on your system is to create a Smart Collection:
File > New Smart Collection
Design Style = Monospaced
Languages include Chinese
Related
Unfortunately, I have no way to check this personally, so I wanted to ask the community about it.
According to RFC 5646, Chinese can have the following representation: zh-Hans for Simplified Chinese, zh-Hant for Traditional Chinese, or more specific: zh-Hans-SG for Simplified Chinese for Singapore, zh-Hant-MO for Traditional Chinese for Macau. This is not an exhaustive set of options, there are many.
One thing I know for sure - Chinese cannot be represented as follows: zh, or zh-CN, or zh-TW and the like.
However, how are things in reality? If the site is visited by a user who speaks Chinese, what can I expect in the Accept-Language header?
Well, I got the Windows Sandbox installed and I was able to install whatever I wanted there.
I checked two browsers:
QQ browser (Chinese is selected by default, I'm not sure which
script).
Google Chrome (added all supported Chinese languages and
made them first on the list).
QQ sends in the request the following content in the accept-language header: zh-CN, zh; q = 0.9.
Google Chrome sends the following content in the accept-language header: zh-CN, zh-TW; q = 0.9, zh-HK; q = 0.8, zh; q = 0.7, en; q = 0.6, also I figured out what Chrome means under the indicated codes:
zh-CN - Chinese (Simplified)
zh-TW - Chinese (Traditional)
zh-HK - Chinese (Hong Kong)
zh - Chinese
To be honest, this is strange, but it is a fact.
I try to localize my project. I have clicked "Use Base Internalization" and added 2 languages: English and French. The English is marked as "Development language" - not sure, maybe I set it, but in the storyboard I use another language (not English). And second difference between these 2 localizations is that English (Development language) has 2 files localized while French has only 1 file localized (screenshot) I checked the app's folder. In the en.lproj
there is only 1 file Main.strings with all my english translations. In the fr.lproj the same thing - only Main.strings but with french translations.
So in the folders everything is correct, but:
1) When I run app with English language - everything works correct. But when I set French language to simulator (or my real device, after deleting the app) nothing works - it shows me my standard storyboard (not English).
2) English localization has 2 localized and I can't understand what is the second file.
The second point is not crucial for me now. I just need to make French localization work
When you add Localization than these file will show
Localizable.strings (English). “Hello ” = “Hello”; (Ex you can write hello )
Localizable.strings (Frech). “Hello ” = “Bonjour”;
Or main string you can change object into freach
Main.strings(English). 3ZR-e4-Gil.text" = "Hello";
Main.strings(Frech). 3ZR-e4-Gil.text" = "Bonjour";
swift
import Foundation
extension String {
func localized(lang:String) -> String {
let path = Bundle.main.path(forResource: lang, ofType: "lproj")
let bundle = Bundle(path: path!)
return NSLocalizedString(self, tableName: nil, bundle: bundle!, value: "", comment: "")
}
}
let str = "Hello".localized(lang: self.language! )
change language via simulator
Or Programmatically change language via app
UserDefaults.standard.set(["en","fr"], forKey: "AppleLanguages")
UserDefaults.standard.synchronize()
SOLVED IT!!! The French localization wasn't used because there was a mistake in the Main.strings (for French) - I missed only one ("). But as in the Main.strings there is no catcher for such a mistakes I didn't get it.
So, it was: "XXX-6r-aEC.text" = "Confirmer;
and I changed it to:"XXX-6r-aEC.text" = "Confirmer**"**;
I'm currently localizing my iOS-Application. This works pretty decent so far.
I've already created localizable.strings and several xib-files and so about 80% of the app is already translated.
But the App also loads data from a WebService which passes me a key, e.g.: "TITEL 1" as well as all supported languages (values) attached to it e.g: "Titel One" "Titel Eins" "Titolo Uno".
And now i would like to store those values in the according localizable.strings files.
For example:
Localizable.strings (English) should then contain:
"TITLE 1" = "Title One";
Localizable.strings (German) should then contain:
"TITLE 1" = "Titel Eins";
Localizable.strings (Italian) should then contain:
"TITLE 1" = "Titolo Uno";
How can I do this?
You will not be able to insert them in the localization strings at run time, if the webserver is managed by you, i suggest that you send wich language is the user using,
Please consider this example
//Get the language code
NSString* languageCode = [[NSLocale preferredLanguages] objectAtIndex:0];
//Now send the request to the server with the language you want
NSString *str = [NSString stringWithFormat:#"www.yourserve.com/yourfunctiom?lang=%#", languageCode];
//Request it
Now basing on the language that you receive in your server you will return the appropriate string
This may be stretching the frameworks a bit, but if you want to use Apple's string loading functions you could try to build an NSBundle in your document directory (a bundle is just a directory, after all), fill it with files from the server and then use NSLocalizedStringFromTableInBundle to get to your strings.
Not sure it is worth it compared to the approach in Omar Abdelhafith's answer, though.
I want to test localization in Indian language in Android.
Following is the file string.xml in values folder
<string name="app_name">नमस्ते</string>
<string name="text_a">परिक्षण</string>
I am using AndroidHindi.ttf font.
I want to display the particular text in hindi in adnroid , but while running I am getting unrendered text .
which particular library should I include to display it properly.
you must download your language font file(.ttf) and put in asset folder.
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Akshar.ttf");
TextView tv = (TextView) findViewById(R.id.CustomFontText);
tv.setTypeface(tf);
tv.setText("Seasonal messages like welcome (நல்வரவு) is used in Kolam. Volunteering to draw kolam at temple is sometimes done when a devotee's");
Source
I have localised my app by adding the correct resource files for various European languages / dialects.
I have the required folder in my project: ./res/com/demo/localization
It contains the required files e.g. Demo.rrh, Demo.rrc, Demo_de.rrc etc.
I want to add support for 2 Chinese dialects, and I have the translations in an Excel file. On iPhone, they are referred to by the codes zh_TW & zh_CM. Following the pattern with German, I created 2 extra files called Demo_zh_TW.rrc & Demo_zh_CN.rrc.
I opened file Demo_zh_CN.rrc using Eclipse's text editor, and pasted in line of the Chinese translation using the normal resource file format:
START_LOCATION#0="开始位置";
When I tried to save the file, I got Eclipse's error about the Cp1252 character encoding:
Save could not be completed.
Reason:
Some characters cannot be mapped using "Cp1252" character encoding.
Either change the encoding or remove the characters which are not
supported by the "Cp1252" character encoding.
It seems the Eclipse editor will accept the Chinese characters, but the resource tool expects that these characters must be saved in the resource file as Java Unicode /u encoding.
How do I add language support for these 2 regions without manually copy n pasting in each string?
Is there maybe a tool that I can use to Java Unicode /u encode the strings from Excel so they can be saved in Code page 1252 Latin chars only?
I'm not aware of any readily available tools for working with BlackBerry's peculiar localization style.
Here's a snippet of Java-SE code I use to convert the UTF-8 strings I get for use with BlackBerry:
private static String unicodeEscape(String value, CharsetEncoder encoder) {
StringBuilder sb = new StringBuilder();
for(char c : value.toCharArray()) {
if(encoder.canEncode(c)) {
sb.append(c);
} else {
sb.append("\\u");
sb.append(hex4(c));
}
}
return sb.toString();
}
private static String hex4(char c) {
String ret = Integer.toHexString(c);
while(ret.length() < 4) {
ret = "0" + ret;
}
return ret;
}
Call unicodeEscape with the 8859-1 encoder with Charset.forName("ISO-8859-1").newEncoder()
I suggest you look at Blackberry Hindi and Gujarati text display
You need to use the resource editor to make these files with the right encoding. Eclipse will escape the characters automatically.
This is a problem with the encoding of your resource file. 1252 Code Page contains Latin characters only.
I have never worked with Eclipse, but there should be somewhere you specify the encoding of the file, you should set your default encoding for files to UTF-8 if possible. This will handle your chinese characters.
You could also use a good editor like Notepad++ or EMEditor to set the encoding of your file.
See here for how you can configure Eclipse to use UTF-8 by default.