Handling the CSV import issue with OSX Yosemite(10.10) and Unity4.X with Smart Localization

Both Smart Localization free and pro supports exporting and importing the language files to .csv. Unfortunately, using Mac OSX 10.10 Yosemite and Unity 4.5 or 4.6 will cause the game engine to crash when importing .csv into the project.
This issue is a bug in unity and has nothing to do with Smart Localization. We have filed a bug report to Unity for this.

However, at this stage you have two options to solve this:

  1. Upgrade to Unity 5.X. The issue seems to be resolved since Unity 5 was released.
  2. Rename your .csv files to the .txt file ending before importing your language files. Smart Localization only looks at what the files are containing and not the file ending.

Choosing one of these options will prevent unity from crashing every time on importing a language file with OSX 10.10 and Unity 4.X.

Posted on June 21, 2015 and filed under Smart Localization.

Making your LanguageManager persist between scenes

The LanguageManager in Smart Localization does not persist between scenes in Unity by default. The original reason why we didn't have the DontDestroyOnLoad flag automatically set in the beginning was that we think that this is a decision best made by the developer. 
The "don't destroy on load" flag is very easy to set, but it's not as easy to revert. To do that, you basically need to delete the object.

Anyway, We created a convenience method for you to set this flag so that it works correctly with our system.

Call LanguageManager.SetDontDestroyOnLoad() somewhere in your code base to set the flag. Preferably when your application is starting up.

This will make the localization system keep its settings and not reset for every new scene you load.

Posted on June 20, 2015 and filed under Smart Localization.

Using the asset override feature in Smart Localization

We created the override asset feature to use when you want to use the same localized asset in multiple languages.
For example, let's say you want to use the same localized audio asset in Swedish as the one you are using in English.

To do this, enter the translation window for Swedish, press the toggle for Override and select the language you want to use the asset from. Don't forget to press save.


Using the plural support in Smart Localisation PRO

Overview of feature

The plural support feature is used to handle strings with different numbers in them. For example: — “I have {0} apples”

This key works fine for when you have zero or more than one apples but becomes “I have 1 apples” if you have exactly one. The string you want in that case is “I have 1 apple” and that is what plural support is trying to solve.

Naming your keys

For the plural form system to pick the correct plural form the keys have to be named in a special way: “[yourKeyName][pluralForm]” ex. “MyAppleSentence3” for plural form 3

Plural forms in editor window

This results in the plural form functions correctly picking the right plural form.

Feature Details

We do this by extending the functions that you use to get strings today. If you add a number after your call to GetTextValue(key) so it becomes GetTextValue(key, count) we figure out what plural form that corresponds to in the currently selected language. We then map your key to that plural form by appending an underscore “” and the number of the plural form. The key “MyAppleSentence” then becomes “MyAppleSentene0” for the first plural form.

Its important to note that plural from number does not correspond directly to the number passed in to the GetTextValue function. “I have 2 apples” resolves to the second plural form for english but so does every call that requests the key with a number over 1. This is because English has two plural forms and the rule for them goes like this:

  • plural from 0 for n=1
  • plural form 1 for n=0 or n>1

To get this in perspective we can look at the Arabic plural form which goes like this:

  • plural form 0 for n=0
  • plural form 1 for n=1
  • plural form 2 for n=2
  • plural form 3 for n%100 >= 3 && n%100 <= data-preserve-html-node="true" 10
  • plural form 4 for n%100 >= 11
  • plural form 5 for everything else

Using the plural system

When you have created the keys for your different plural forms all you have to do to use them is to add another parameter to the functions you usually use when getting strings from keys.

And plural forms of course works not just on string values but on any of the localized keys in your game.

Here is a list of the function signatures for the basic plural functions:

string GetTextValue(string key, int count);
TextAsset GetTextAsset(string key, int count);
AudioClip GetAudioClip(string key, int count);
GameObject GetPrefab(string key, int count);
Texture GetTexture(string key, int count);

Caveat

If you have a key that uses plural forms and you support languages with different number of plural forms there will be some empty keys in the languages with less forms.

This is needed because of the root keys system and also because of bulk export to single csv/xls to have rows match even in languages which doesn’t have a use for that many plural forms.

Defining your own plural function

In addition to providing the plural functions for each supported language we also expose an overloaded function for getting a key and defining your own plural rule.

string GetTextValue(string key, int count, Func<int, int> pluralForm);
TextAsset GetTextAsset(string key, int count, Func<int, int> pluralForm);
AudioClip GetAudioClip(string key, int count, Func<int, int> pluralForm);
GameObject GetPrefab(string key, int count, Func<int, int> pluralForm);
Texture GetTexture(string key, int count, Func<int, int> pluralForm);

These are great to have if you want to define an arbitrary rule for a specific key. Take these keys for example:

  • “Unread_0” = “No unread messages”
  • “Unread_1” = “One unread message”
  • “Unread_2” = “{0} unread messages”
  • “Unread_3” = “Over one hundred unread messages”

To get these to work correctly you will have to define your own plural rule since it doesn’t correspond to any language defined plural rule.

string messages = languageManager.GetTextValue(“Unread”, unreadMessages, (n) => n==0 ? 0 : n==1 ? 1 : n>100 ? 3 : 2);

Or you can store the plural rule for later use

Func<int, int> customRule = (n) => n==0 ? 0 : n==1 ? 1 : n>100 ? 3 : 2;
string messages = languageManager.GetTextValue(“Unread”, unreadMessages, customRule);

If you want more details about handling plural forms in localization you can go to this link: http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html

If you have any questions about this feature or anything else don’t hesitate to contact us via e-mail or the comments below.

Using the Watch-file feature in Smart Localization PRO

Smart Localization PRO comes with a watch-file feature. This means that you can edit your .csv files in any csv compatible editor you'd like, and the game will instantly pick up your changes. This short tutorial will show you how to use it.

First off, you'll need to create a csv file that corresponds with your translated language. Open up the main Smart Localization window and press export. Save your file at a location of your choice. 

 

After you've done this, navigate to a scene that uses the Smart Localization in your UnityProject and press play. I'll use the LoadAllLanguages.unity scene that comes with the unitypackage.

 

Once the scene is started, open up the translation window for the selected language and press "watch file for changes". Navigate to your exported .csv file and select it using the popup that was brought up when you clicked the button.

Finally, open up the file you've selected to be watched in a csv editor of your choice. I'll use notepad++ for this tutorial.

Now when you change and save the values in the watched file, it will be instantly reflected in your game!


Posted on March 15, 2015 and filed under Smart Localization.

The future of Smart Localization

First I would like to thank the whole community for all the great response and feedback we’ve gotten; this is what keeps us working on and improving the plugin :)

Going forward
Soon we will be launching a PRO version of Smart Localization on the asset store. We do not have a date yet but it should be out this year :)

FREE version
The free version will continue to get updated with new features and stability fixed. Our goal is to continue with the free version as we have been and hopefully being able to devote more time to it. Nothing will get removed from the free version and we do want the free version to be adequate for most small teams and even bigger ones. The pro version will be aimed at improving  productivity and flexibility of the plugin.

PRO version
The pro version will get more advanced features that improves the speed and convenience of the plugin. Some examples include Google Sheets, multi language editing window and hot loading CSV files from the file system.

We would love to know what you guys think about all this.

Comment below or head over to our unity3D forum post here.

// Jakob(@zuric) Niklas(@niklasborglund)

Posted on October 26, 2014 .

Getting started with Smart Localization 2.x for Unity3D

There has been quite some changes with the Smart Localization project since version 1.x. First of all, the development is no longer handled by Cry Wolf Studios. Since we decided to liquidate the studio, me(Niklas Borglund) and Jakob Hillerström decided to take over the project and release it under the developer name janeTech.

As I mentioned above, there's been some changes to the project since then. The biggest ones are:

  • We are not using the System.Globalization.CultureInfo class anymore. We are using our own class called SmartCultureInfo.

  • Everything is now encapsulated within the namespaces SmartLocalization and SmartLocalization.Editor

  • The ability to Export/Import/Update CSV files

  • Completely reworked ground for increased stability.

  • Translation Window can be used at runtime (2.1 and above)

  • Completely reworked GUI with features such as resizable column widths (2.1 and above)

To get started with Smart Localization you will have to start by downloading the project from the asset store and importing it to your project.

Once you've done that, navigate to Window->Smart Localization.

 

The window will prompt you to create a Smart Localization workspace if you haven't done so already. Follow the instructions until you see the main localization window.

Press the Edit Root Language File button. This will bring up a new window where you create all the keys and root values along with the key types for your project. We'll start by adding two keys; SmartLocalization.Welcome and SmartLocalization.LocalizedString.

Once you've done that, press save and return to the main localization window.

Now it's time to create some languages. For the purpose of this tutorial, we'll create two languages; English and Swedish. Find the two cultures in the Add/Update Languages scroll list and press Create on each one.

Now press the 'Translate' button placed on the English culture row. A new window will be brought up. Since we wrote our root values in english, all we have to do here is to press the "Copy All Values From Root" – button. Don't forget to press save and return to the main window.

Now do the same procedure with Swedish. Press Translate and write the Swedish values in the 'Value' column. If you don't know Swedish, just copy what it says in the image below or write whatever value you want. Again, don't forget to press save when you are done.

That's basically all the setup you need to get started. By now, you can open the scene LoadAllLanguages.unity that can be found in the Smart Localization package from the store and you should see the created values in the scene when you press play.

Next I'll show a basic and easy way to get the localized values from code. I'll start by creating a new script called SmartLocTutorial.cs. In the script we'll load the english language and print the two localized strings we created earlier.

Adding this script to an empty game object in your scene should produce the following output.

What if you want to switch to the swedish values at runtime? Simplest way to do that would be to expand the OnGUI method in our SmartLocTutorial script.

Play your scene again, press the Swedish button, and you should see the Swedish values on the screen.

Posted on September 16, 2014 and filed under Smart Localization.

Smart Localization v.2.004 submitted to the Asset Store

We've submitted an update to the asset store.

Changelist v.2004
------------------------------------
* Made fix for event issue when changing language on iOS (JIT-Compile issue)
* Fixed multiline issue for text lines in the translate window
* Fixed multiline issue in CSV Import/Export

You can now simply press enter in the translate window to get a new line.

If you need the update before it hits the store, contact us and we'll send it to you.

Posted on August 7, 2014 and filed under Smart Localization.