Unity NGUI Localization

Intro

Currently working on localization, just to share my implementation.

There are some advanced ways doing so as well, e.g. CSV support was added in 3.5.0. But this time I am still working with txt version.

Basic

We will need Unity3D installed and equipped with NGUI 2.7.0+
We will meet these two classes:
Localization is the manager class where we set up localization information, langauges, localized string resource.

UILocalize

Setup

We need to prepare our localized strings, format goes like this: KEY = string

locale-en.txt
play = play
start_game = Start Game
pause = Pause
restart = Restart
options = Options
locale-cn.txt
play = 玩游戏
start_game = 开始游戏 
pause = 暫停 
restart = 重新啟動 
options = 选項

If you want to include leading space in your localized string, you can hack like this:

scores =^    分数

Attach Localization class

Attach the Localization manager to your game, it works as a singleton.

Create a GameObject, attach Localization script to that object.

Setup the locale resource file. In this case, I have 3 locales to work on.

Snippet from Localization.cs
if (mInstance == null)
                {
                    GameObject go = new GameObject("_Localization");
                    DontDestroyOnLoad(go);
                    mInstance = go.AddComponent<Localization>();
                }

It creates a "_Localization" object in your game and stay alive through out the whole game after initilization.

So, we don't need to define it everywhere in the game. (but you still can define it in your separated scene for testing purpose. Note that if a Localization instance is alive, a new one WILLNOT be initialized)

Attach UILocalize

I have a UILabel which displays "Start Game"

I want to translate "Start Game" into a different language.
Let's attach a script and set up the KEY

Assign Language

There are several ways to detect/ pick languages.
NGUI also provides a helper, NGUI LaguageSection. It helps you to create a drop down list for languages.

For iOS game, I detect language using this little script:
Current device language in iOS @ StackOverflow

After you figured out which locale to use, set current in Localization instance.

Localization.instance.currentLanguage = "locale-cn";

Run

Build and run your game.

This also works on UISprite and UIButton.

comments powered by Disqus

知足 - 編曲習作

又是五月天的歌
(好像是因為本身Rock底的關係所以比較容易入手)

其實是真的要到開始玩錄音的時候,才會意會到自己的拍子感有差。
所以 Root還是Basic 的Drum loop + electronic piano + string

最近被同事薰陶下開始進入少許電子音樂的世界
所以這次也試加了點電子的synthesiser
效果好像... 還交融得到 XD


知足

作詞:阿信
作曲:阿信

怎麼去擁有 一道彩虹
怎麼去擁抱 一夏天的風
天上的星星 笑地上的人
總是不能懂 不能覺得足夠

如果我愛上 你的笑容
要怎麼收藏 要怎麼擁有
如果你快樂 不是為我
會不會放手 其實才是擁有

當一陣風吹來 風箏飛上天空
為了你而祈禱 而祝福 而感動
終於你身影 消失在 人海盡頭
才發現 笑著哭 最痛

comments powered by Disqus

突然好想你 (relief version) - 編曲習作

輕輕來個重編音樂版
比較輕鬆的編排

覺得後段比較好聽,
總是不知怎樣把intro做好...


突然好想你 - 五月天

作詞:阿信(五月天)
作曲:阿信(五月天)

(Intro)

最怕空氣突然安靜 最怕朋友突然的關心
最怕回憶 突然翻滾絞痛著不平息 最怕突然 聽到你的消息

突然好想你 你會在哪裡 過得快樂或委屈
突然好想你 突然鋒利的回憶 突然模糊的眼睛

(Bridge)

我們像一首最美麗的歌曲 變成兩部悲傷的電影
為什麼你 帶我走過最難忘的旅行 然後留下 最痛的紀念品

突然好想你 你會在哪裡 過得快樂或委屈
突然好想你 突然鋒利的回憶 突然模糊的眼睛

comments powered by Disqus

Save GIF image data to Camera Roll

We often use this piece code to save UIIMage to camera roll:

    UIImageWriteToSavedPhotosAlbum([UIImage imageWithData:ImageData], self,@selector(image:didFinishSavingWithError:contextInfo:), nil);

However when we meet GIF, we need to use :

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library writeImageDataToSavedPhotosAlbum:ImageData metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
        // Continue as normal...
    }];
comments powered by Disqus
comments powered by Disqus