Tasharen Entertainment Forum

Support => NGUI 3 Documentation => Topic started by: ArenMook on February 14, 2014, 04:45:59 AM

Title: Localization system
Post by: ArenMook on February 14, 2014, 04:45:59 AM
Overview

Localizing your game using NGUI is as simple as creating a CSV file with all your text and using the UILocalize component on your labels and sprites that you want to be localized.

NOTE: The CSV support was added in 3.5.0

(http://www.tasharen.com/ngui/csv.jpg)

The first step is creating the CSV file. You can use Google Docs, Excel, or any other application that's capable of creating excel style files.

The CSV file should contain two or more columns. The first column should contain keys that you will use in the Key field of the UILocalize component. Other columns should contain the actual localized values for those keys.

The first row should contain your language names -- English, French, Simplified Chinese, etc. When you want to switch a language in-game you can either use Localization.language = "English;" (or any other language defined in the first row), or just attach the LanguageSelection component to a drop-down list, turning it into a language selection list.

All other rows should contain the key in the first column and text values in all the subsequent columns. Just make sure that there are localized values present for all the given keys, or things may not work properly.

Once you're done, export the file in CSV file format as Localization.csv, and place it in the Resources folder. Unity 4 treats CSV files as Text files, but if you are still on Unity 3, you will need to rename that file to have a TXT extension or it won't be recognized.

To localize any label or sprite, attach UILocalize script to it and choose a key defined in the CSV file you created, and that's it! The label or sprite's value will be pulled from the localization file automatically, and when you switch languages, so will your label or sprite.

Pro-Tip #1

If you don't remember what your key was, just start typing in the UILocalize's "key" field. It will bring up a list of relevant entries for your convenience. Click on one of them to choose that value. Likewise you can click on the Preview options to have the localized object immediately assume that value.

Pro-Tip #2

If you are doing custom localization, you can still use the localization system. Use Localization.Get(key) anywhere in code to retrieve a localized value for the current language. To change the language -- Localization.language = "New Language";

Pro-Tip #3

Want even better localization tools? Have a look here -- http://www.tasharen.com/forum/index.php?topic=8324.0

Class Documentation

http://tasharen.com/ngui/docs/class_u_i_localize.html
http://tasharen.com/ngui/docs/class_localization.html

If you have a question regarding this component or would like me to clarify something, just post a reply here.
Title: Re: Localization system
Post by: nkls on February 21, 2014, 03:34:53 AM
Great update. The preview and the support of csv´s in 3.5 are awsome. 
Got one question. I´ve managed to read my localization from a csv (saved from google spreadsheet) , but I cant get the line break to work on my localized labels  :/
I´ve tried \n , but doesnt seems to work.. Any advice on this?
I
Title: Re: Localization system
Post by: ArenMook on February 21, 2014, 11:39:37 AM
Open ByteReader.cs, and add this line after line 180:
  1.                         string line = ReadLine();
  2.                         if (line == null) return null;
  3.                         line = line.Replace("\\n", "\n"); // <-- this one
Title: Re: Localization system
Post by: SketchWork on February 21, 2014, 11:54:28 AM
CSV localization is much better - thanks for adding this.  One question though.

How expensive is calling UILocalize on every label, button, list, etc on mobile?
Title: Re: Localization system
Post by: dxlong on February 22, 2014, 03:25:28 AM
Use Localization.Get(key) in code can't get Chinese character!  :(
Title: Re: Localization system
Post by: ArenMook on February 22, 2014, 11:24:09 AM
It can if your code file is saved with proper encoding.
Title: Re: Localization system
Post by: ZachHoefler on February 26, 2014, 02:05:17 PM
I was having trouble with this until I realized NGUI was loading NGUI/Resources/Localization.csv instead of my Resources/Localization.csv file =] Deleting the NGUI example file fixed the issue for me.

Figured I'd post here in case anyone else was having the same problem.
Title: Re: Localization system
Post by: Ferazel on February 26, 2014, 08:54:29 PM
I hope you don't get rid of the old key = value formatting because it works for some projects better than having all of the languages in the same file. If you're like us and have a potentially gigantic string table and don't want to keep all of the strings in memory for every language. Could you try to include the mechanics for loading the old style of languages as well in the documentation? You can delete this post after you do.

If you want to use the old localization format. You can having a .txt file in the resources directory that is the same name as you set to Localization.language. So if you have a English_US.txt file located in the Resources directory you can load this string table by setting the language: Localization.language = "English.US";

ProTip: If you don't want to put the language at the root level of the Resources directory you can set the language to be the filepath to the resource such as: Localization.language = "Strings/English_US";
Title: Re: Localization system
Post by: Bradamante3D on February 27, 2014, 06:38:01 PM
It also seems the Localization in the UI Starter Kit: Starlink is broken. It complains with Localization.cs, line 408 (Localization key not found: "Quit") for any key you try.

Does that mean that the UI Starlink Kit is not compatible with new versions of NGUI or does it simply not work out of the box, but it would with some manual adjustments?
Title: Re: Localization system
Post by: ArenMook on February 27, 2014, 06:54:23 PM
It means I totally forgot to update it. My bad, I'll do that tonight.
Title: Re: Localization system
Post by: rptts on March 03, 2014, 02:16:49 PM
Hello,

I'm having some trouble making my localization system to work properly. Maybe I'm doing something wrong, but here's what I'm doing:

(I'm using unity 3.5)
In the Awake of my app i do:

  1. TextAsset languages = Resources.Load("myLanguages", typeof(TextAsset)) as TextAsset;
  2.                        
  3. Localization.LoadCSV(languages);
  4.  
  5. Localization.language = Localization.knownLanguages[0];
  6.  

but every time I instantiate a new UIPopupList (when i load a new scene, for example), it seems that the Localization forgets the dictionary because it no longer recognizes the keys. I get the warning from Localization.cs, line 408 (Debug.LogWarning("Localization key not found: '" + key + "'");)
Am I doing something wrong here?

Another thing that I would like to clarify is how can I change a localized string ("my string number {0}") when I change the Language dynamically (for example using UIPopupList). Before this last update I was updating it on the OnLocalize function, using the
  1. label.text = string.Format(label.text, 1);
method, but now it seems it "localizes" the label after the OnLocalize function, because although when I output the label to the console, the string is correct, but in the game interface it shows the original string.
Title: Re: Localization system
Post by: ArenMook on March 04, 2014, 12:31:18 AM
Don't do any coding. Simply call your CSV file "Localization.txt". It needs to have the "TXT" extension for Unity 3.5. NGUI will load this file from resources automatically. Also make sure that you don't already have Localization.txt from NGUI's examples. It will conflict with your own.
Title: Re: Localization system
Post by: rptts on March 04, 2014, 07:33:06 AM
I've made the pretty noob mistake of saving my settings prefab while I was playing the app and saved the UIPopupList with the onChange Event to notify the LanguageSelection delegade and OnChange methods. That was causing the problem, after removing them it's now working properly.

Anyway, sometimes simplifying things makes us realize easier where our problems are, tnx  :D
Title: Re: Localization system
Post by: syslord2k2 on March 10, 2014, 11:57:20 AM
I tried to use this system but it didn't work at all. After doing some logging i found out that it would only ever read the first line and nothing else. I attached the used Localization.csv and hope that somebody can help me.
Title: Re: Localization system
Post by: ArenMook on March 10, 2014, 09:31:19 PM
That's not a CSV file. CSV = Comma Separated Values. Your values are separated by a semicolon.
Title: Re: Localization system
Post by: syslord2k2 on March 11, 2014, 05:07:16 AM
It seems that in germany semicolon is the standard setting for list seperators, i had to change it to comma in the windows regional settings so excel would give me csv... thanks for the help
Title: Re: Localization system
Post by: dt1000 on March 12, 2014, 10:53:32 PM
Well this has got me totally stumped - after an hour of experimentation, I have nothing to show for it.
Could somebody be mega awesome and post a list of all the precise steps that need to be taken to get this to work?

Where, exactly, do I have to put Localization.csv?
Do I need to have an object with the Localization script on it? (As well as the UILocalize script on whatever I want to localize).

The demo I have still seems to be using the old style localization... even though I am pretty sure I have the latest NGUI...

Please help, this is driving me nuts.

Thanks,
Dan
Title: Re: Localization system
Post by: ArenMook on March 13, 2014, 12:26:25 AM
By default when you import NGUI's examples, it will import the Localization.csv file along with it in NGUI/Examples/Resources folder. This localization file will be loaded by default. If you create your own localization file, be sure to delete the file in the Examples folder first.
Title: Re: Localization system
Post by: dt1000 on March 13, 2014, 07:00:03 AM
Aaaaaaaaah, looks like I was on version 3.4.9. Sorry.
Thanks for the tip ArenMook - that was the proverbial slap in the face I needed!
Oy...
 :-[
Title: Re: Localization system
Post by: luvcraft on March 19, 2014, 07:47:04 PM
Just wanted to let you know that ByteReader (v3.5.4 r2) was throwing null reference exceptions for me at line 202, so I changed:
  1. line = line.Replace("\\n", "\n");
  2. if (line == null) return null;
  3.  
to
  1. if (line == null)
  2.    return null;
  3. else
  4.    line = line.Replace("\\n", "\n");
  5.  
and then it was happy. I'm posting this here because it looks like some code you posted further up in this thread, but with two lines swapped. And now that I think about it, I should have just swapped those two lines and left out the "else"...

I suspect a similar problem might crop up at line 194.
Title: Re: Localization system
Post by: ArenMook on March 21, 2014, 04:13:34 PM
Thanks, I'll fix it on my end.
Title: Re: Localization system
Post by: dandrea on March 24, 2014, 05:08:42 PM
Just to report: using Localization.csv file didn't do it. I had to rename the file to .txt in order to get it working.

Unity 4.2, NGUI 3.5.5.
Title: Re: Localization system
Post by: XPEC02 on April 03, 2014, 04:53:28 AM
Hi, I have a question about comma.
If one value contains a comma like "Hello, world".
How to avoid the csv parsing problem?
Title: Re: Localization system
Post by: ArenMook on April 03, 2014, 09:58:21 PM
Wrap it in quotes.
Title: Re: Localization system
Post by: ArenMook on April 09, 2014, 03:17:33 AM
For those that want a convenient way of updating their old style localization to the new one, this convenience script may help:
  1. using UnityEngine;
  2. using System.IO;
  3. using System.Collections.Generic;
  4.  
  5. public class CreateCSV : MonoBehaviour
  6. {
  7.         public TextAsset[] assets;
  8.  
  9.         Dictionary<string, string> ReadDictionary (TextAsset asset)
  10.         {
  11.                 ByteReader reader = new ByteReader(asset);
  12.                 return reader.ReadDictionary();
  13.         }
  14.  
  15.         void Assign (Dictionary<string, string[]> full, string key, string value, int index, int max)
  16.         {
  17.                 if (!full.ContainsKey(key)) full[key] = new string[max];
  18.                 full[key][index] = value;
  19.         }
  20.  
  21.         [ContextMenu("Execute")]
  22.         public void Execute ()
  23.         {
  24.                 Dictionary<string, string[]> full = new Dictionary<string, string[]>();
  25.  
  26.                 for (int b = 0; b < assets.Length; ++b)
  27.                 {
  28.                         Dictionary<string, string> dict0 = ReadDictionary(assets[b]);
  29.                         foreach (KeyValuePair<string, string> key in dict0)
  30.                                 Assign(full, key.Key, key.Value, b, 2);
  31.                 }
  32.  
  33.                 StringWriter writer = new StringWriter();
  34.  
  35.                 writer.Write("KEY");
  36.                 for (int i = 0; i < assets.Length; ++i)
  37.                         writer.Write("," + assets[i].name);
  38.                 writer.Write("\n");
  39.  
  40.                 foreach (KeyValuePair<string, string[]> pair in full)
  41.                 {
  42.                         writer.Write("\"" + pair.Key + "\"");
  43.  
  44.                         for (int i = 0; i < assets.Length; ++i)
  45.                         {
  46.                                 string val = pair.Value[i];
  47.                                 if (string.IsNullOrEmpty(val)) val = pair.Key;
  48.                                 writer.Write(",\"" + val.Replace("\n", "\\n") + "\"");
  49.                         }
  50.                         writer.Write("\n");
  51.                 }
  52.  
  53.                 StreamWriter file = new StreamWriter("Assets/Resources/Localization.txt", false, System.Text.Encoding.UTF8);
  54.                 file.Write(writer.ToString());
  55.                 file.Flush();
  56.                 file.Close();
  57.         }
  58. }
I wrote it for myself so that I can merge Starlink's localization files into a single CSV file.

To use it, just attach it to any game object, reference the text files you want to merge, right click the script and choose "Execute". The result will be saved in "Assets/Resources/Localization.txt" -- you may want to change that if you want it elsewhere.
Title: Re: Localization system
Post by: Genesia on April 14, 2014, 03:50:11 AM
Hello,

There is 2 problems with the new localization system :

1) The localization file must be renamed from .CSV to .TXT or it is not recognized by unity (Unity 4.3.4).

2) In the Localization.CSV file, my keys are separated by ";" semicolon (the standard of CSV format) and in your "ByteReader.cs" file your code read "," comma for separate the keys.

Do I miss something ?

  1. public BetterList<string> ReadCSV ()
  2.         {
  3.                 mTemp.Clear();
  4.                 string line = "";
  5.                 bool insideQuotes = false;
  6.                 int wordStart = 0;
  7.  
  8.                 while (canRead)
  9.                 {
  10.                         if (insideQuotes)
  11.                         {
  12.                                 string s = ReadLine(false);
  13.                                 if (s == null) return null;
  14.                                 s = s.Replace("\\n", "\n");
  15.                                 line += "\n" + s;
  16.                                 ++wordStart;
  17.                         }
  18.                         else
  19.                         {
  20.                                 line = ReadLine(true);
  21.                                 if (line == null) return null;
  22.                                 line = line.Replace("\\n", "\n");
  23.                                 wordStart = 0;
  24.                         }
  25.  
  26.                         for (int i = wordStart, imax = line.Length; i < imax; ++i)
  27.                         {
  28.                                 char ch = line[i];
  29.  
  30. // Thomas : HERE MUST BE ';' ?
  31.                                 if (ch == ',')
  32.                                 {
  33.                                         if (!insideQuotes)
  34.                                         {
  35.                                                 mTemp.Add(line.Substring(wordStart, i - wordStart));
  36.                                                 wordStart = i + 1;
  37.                                         }
  38.                                 }
  39.                                 else if (ch == '"')
  40.                                 {
  41.                                         if (insideQuotes)
  42.                                         {
  43.                                                 if (i + 1 >= imax)
  44.                                                 {
  45.                                                         mTemp.Add(line.Substring(wordStart, i - wordStart).Replace("\"\"", "\""));
  46.                                                         return mTemp;
  47.                                                 }
  48.  
  49.                                                 if (line[i + 1] != '"')
  50.                                                 {
  51.                                                         mTemp.Add(line.Substring(wordStart, i - wordStart));
  52.                                                         insideQuotes = false;
  53.  
  54. // Thomas : HERE MUST BE ';' ?
  55.                                                         if (line[i + 1] == ',')
  56.                                                         {
  57.                                                                 ++i;
  58.                                                                 wordStart = i + 1;
  59.                                                         }
  60.                                                 }
  61.                                                 else ++i;
  62.                                         }
  63.                                         else
  64.                                         {
  65.                                                 wordStart = i + 1;
  66.                                                 insideQuotes = true;
  67.                                         }
  68.                                 }
  69.                         }
  70.  
  71.                         if (wordStart < line.Length)
  72.                         {
  73.                                 if (insideQuotes) continue;
  74.                                 mTemp.Add(line.Substring(wordStart, line.Length - wordStart));
  75.                         }
  76.                         return mTemp;
  77.                 }
  78.                 return null;
  79.         }
  80.  

Thanks,
Thomas ZIGHEM.


Unity 4.3.4 / NGUI 3.5.7
Title: Re: Localization system
Post by: ArenMook on April 14, 2014, 04:05:29 AM
CSV = Comma Separated Value. If it was Semicolon Separated Value, it would be SCSV :P
Quote
The name "CSV" indicates the use of the comma to separate data fields. Nevertheless, the term "CSV" is widely used to refer a large family of formats, which differ in many ways. For example, many so-called "CSV" files in fact use the tab character instead of comma (such files can be more precisely referred to as "TSV" for tab separated values); some implementations allow or require single or double quotation marks around some or all fields; and some reserve the very first record as a header containing a list of field names. The character set being used is undefined: some applications require a Unicode BOM to enforce Unicode interpretation (sometimes even a UTF-8 BOM, even though technically that's an oxymoron.)

Other implementation differences include handling of more commonplace field separators (such as space or semicolon[4]) and newline characters inside text fields.[5] One more subtlety is the interpretation of a blank line: it can equally be the result of writing a record of zero fields, or a record of one field of zero length; thus decoding it is ambiguous.
Quote
Adjacent fields must be separated by a single comma. However, "CSV" formats vary greatly in this choice of separator character. In particular, in locales where the comma is used as a decimal separator, semicolon, TAB, or other characters are used instead.
Source: http://en.wikipedia.org/wiki/Comma-separated_values

P.S. My Unity 4.3.4 recognizes CSV as a text file. I only had to rename it to TXT for Unity 4.2 and earlier versions.
Title: Re: Localization system
Post by: Genesia on April 14, 2014, 04:54:20 AM
CSV = Comma Separated Value. If it was Semicolon Separated Value, it would be SCSV :PSource: http://en.wikipedia.org/wiki/Comma-separated_values

P.S. My Unity 4.3.4 recognizes CSV as a text file. I only had to rename it to TXT for Unity 4.2 and earlier versions.

I have try just right now, and that work, my bad.

So, I was confused with comma / semicolon because when i save a CSV file with 'NUMBERS (from apple)" all keys are separated buy ";" not "," and my translate file contain more thousand of sentences like this :

KEY column : TempleNPC_ClosedBuilding
FR column : Notre Roi a eu vent de la construction de ce temple, il nous envoie un grand prêtre par le prochain bateau. Revenez plus tard
EN column : Our King has heard about the construction of this temple, he sends us a high priest by the next boat. Please come back later

Sentences contain a lot of comma... I have read the tips about i need to surround my texts with quotes, but you see the work :p

Anyway, thanks for your reply and your nice job on NGUI.

Thomas ZIGHEM.

Title: Re: Localization system
Post by: ArenMook on April 15, 2014, 10:11:38 AM
I advise using Google Docs. Create a spreadsheet there, and do everything there. Not only it lets you share it with others, you can also collaboratively edit it with multiple people.

And when you save it, it uses the proper format that NGUI reads.

Here is the entire localization file for Starlink, for example: https://docs.google.com/spreadsheet/ccc?key=0AmTyhvfb_nj5dHh4WmlKS0I3cVFLWkxZSDdIQ1MzY2c&usp=sharing
Title: Re: Localization system
Post by: luizfranca on May 05, 2014, 09:57:33 AM
This probably is a silly question but, am I doing anything wrong?

I wrote the following script and it says that the key was not found

Localization.language = "Portuguese";
Debug.Log(Localization.get("achievement titles 0.0.0"));

I copied and pasted the key from the cvs file and the localization file is in the resource folder and there is not other localization file in the project.

Title: Re: Localization system
Post by: ArenMook on May 06, 2014, 12:04:31 AM
What does the contents of your localization file look like?
Title: Re: Localization system
Post by: AniOSGeek on May 07, 2014, 05:47:34 AM
I have developed a simulation game with all menus done on NGUI(2.3.3). Now i want to localize my game in Turkish language. I have use location Object on my scene and loading string values(label text) from strings file(Turkish.txt).
Its loading right words but few words are missing on text for example Coin Alýn is showing like Coin Aln and Çöl Sürüþü is showing just lSr. So its missing every character with some symbols on it.
Can someone help me how can i get it working fine.
I am using dynamic fonts(BebasNeueregualr).   
Thanks
Title: Re: Localization system
Post by: vallcrist on May 07, 2014, 08:36:23 AM
Hello Michael,

Is there a way to load the localization file dynamically, e.g. from the internet at runtime? We would like to be able to change the localization values and add some dynamic content to them withuot having to make a new build everytime. :T
Title: Re: Localization system
Post by: ArenMook on May 08, 2014, 03:22:29 AM
@AniOSGeek: I can't help you much with such an old version of NGUI, and NGUI 2 is no longer supported at all. However there are two causes of that. First -- your file is not saved as UTF-8. Second -- your font doesn't have the necessary glyphs to render those special characters.

@vallcrist: Of course. Localization.LoadCSV(textAsset) for a CSV dictionary or Localization.Load(textAsset) for a single file.
Title: Re: Localization system
Post by: Spirit117 on June 03, 2014, 07:48:42 AM
Hello!

I've been at this for a few hours, and I need a hand.

I've made the csv (see attached), and I've created a folder in assets called resources, and I've put the csv in there, and I've tried using the localization prefab object and creating an array of one on it and dragging the file in there (and I've also tried not using the localization prefab object). No matter how I do it:

the UILocalize does not auto-suggest the keys that I've written
Nothing is changed or displayed when I run the game and I get
"Localization key not found - "blah blah""

What am I doing wrong?
Title: Re: Localization system
Post by: ArenMook on June 04, 2014, 02:02:38 AM
Did you delete the Localization.csv file that comes with NGUI? If you didn't, it won't be clear which one will be loaded.

I'm also not clear on what you mean by "localization prefab". Localization is a static class. You can't put it on a game object. If you can, then you are using an old version of NGUI and need to update.
Title: Re: Localization system
Post by: sinok426 on June 26, 2014, 03:54:50 AM
Hello!

I have the same problem with Localization, it doesn't work any more.

The first time I try to use it with the example scene, it works perfectly, so I've replaced the Localization.txt file by a custom Localization.csv file to try the csv, and it also works. Great!
But after moving the csv file in my Assets/Resources folder (and deleting the old one in NGUI examples folder), Localization was broken. It looks like it only reads the first line (KEY,English,Français, etc...), all the other keys are not found (in inspector preview and at runtime).

No idea of what happens, I was a bit lost, so I decided to delete NGUI plugin and reimport the same version of NGUI. But it did'nt solve the problem, the Localization doesn't work even in the example scene.

I'm using NGUI 3.5.9 & Unity 4.3.2

Any ideas of what is the problem ?

Title: Re: Localization system
Post by: keop on June 26, 2014, 09:11:47 AM
Hi,

I was reading this thread today because of the very same problem.
Now I solved it, first I had to remove the Localization.txt file inside Assets/NGUI/Resources folder, second I created a Resources folder inside Resources folder (yeah, it sounds weird, but it works) and created a Localization.txt file there (Assets/Resources/Resources/Localization.txt).
For some reason, it doesn't work at Asset/Resources/Localization.txt path, maybe a bug?

Hope it helps.
Title: Re: Localization system
Post by: ArenMook on June 26, 2014, 11:41:54 AM
All NGUI does is calls Resources.Load("Localization") on line 118 of Localization.cs. This will work as long as you only have one file called Localization.

If the inspector preview is not able to read the Localization file beyond the first line, then I suggest checking your file's line endings.
Title: Re: Localization system
Post by: sinok426 on June 26, 2014, 12:30:02 PM
Thanks for the answers!

The Resources loading for the Localization file is working, no problem with this.
When I change the first line by adding new languages, it shows me all the languages in the UI popup list when I play the example scene, but all the other keys (Flag,Sound,etc...) are not found even with the original Localization.txt file that goes with NGUI (so it's not a problem with this file also).

It looks like i've broken something but I can't see what... I've only one Localization file in my project, and a freshly imported NGUI version without any modifications.
I think my last chance is to try an update of unity and NGUI  :-\
Title: Re: Localization system
Post by: keop on June 27, 2014, 02:47:49 AM
When I make changes in the Localization.txt file, I have to run the player and then stop it to refresh the new localization content.
Maybe it helps you.
Title: Re: Localization system
Post by: sinok426 on June 27, 2014, 07:53:36 AM
So, I find a way to solve the problem  ;D
It had nothing to do with NGUI, the problem was my unity project that was "corrupted".

The only thing I had to do was to replace my old ProjectSettings.asset file in the ProjectSettings folder by a standard one(from a blank project).
But I can't explain why the only thing that did'nt work in my project was the NGUI localization. Solved!
Title: Re: Localization system
Post by: pretender on September 23, 2014, 04:32:48 AM
Hi Aren!

Can you tell me whats wrong with this localization file?

  1. KEY,English,Spain
  2. ID_HELP,"Help","Ayuda"
  3. ID_SETTINGS,"Settings","Ajustes"

File is utf8, I have Label with UILocalize script and key set to ID_HELP
I also have pop up list that has LanguageSelection script on it

In run time i get this warning: "Localization key not found: 'ID_HELP'"
Also pop up list doesn't display available languages
I tried to place Localization.csv to Assets/Resources and as well in the NGUI Examples/Resources folder where original Localization.csv was (until I deleted it)

Thanks!
Title: Re: Localization system
Post by: ArenMook on September 23, 2014, 12:49:18 PM
Nothing is wrong with the localization file. Change the extension to TXT rather than CSV just to be safe, and double-check to make sure you don't have any other Localization.txt files anywhere else. I know you said you deleted it, but that's the #1 reason for it. When in doubt, loop through the keys in the localization file to see what it's loading.
Title: Re: Localization system
Post by: pretender on October 04, 2014, 03:58:10 AM
Is it possible to use multiple localization files?
Title: Re: Localization system
Post by: ArenMook on October 04, 2014, 08:10:22 AM
The new consolidated localization system pulls everything from one file containing all the text. You can have multiple files if you use the old approach instead, but then you won't have a list of languages to work with. You can also set your own localization data at run time if you prefer -- then this data can come from anywhere.

For example in Windward, the first person to host the game actually sends their localization file to everyone else, so that if the host made any modifications, others will receive them automatically.
Title: Re: Localization system
Post by: pretender on October 04, 2014, 08:17:36 AM
your localization system is very convenient and I would like to use it for more complex things (not just in game menus, or simple dialogs..) that would need multiple  spreadsheets and localization files for easier management, because data I want to be localized is logically separated in multiple spreadsheets and using one file would be very hard to manage. Do you have any plans in updating this system to be able to use multiple data files? Is it going to take too much time?

Thanks!
Title: Re: Localization system
Post by: ArenMook on October 05, 2014, 09:14:02 AM
I would suggest you create a different class for this. You can use ByteReader.ReadCSV to parse a CSV file into a dictionary of data for you to use. It doesn't have to be done through the Localization class.
Title: Re: Localization system
Post by: rextr on October 11, 2014, 02:48:58 PM
Hi,

I have just switched from 3.4.9 to 3.7.3, but I couldn't get the old style localization work. I couldn't find any documentation on the old style localization. Someone here suggest putting the language files to the Resources folder, but still doesn't work. It says  "Localization key not found: 'some_key' "

I set Localization.language = "English"; in awake function and I have "English.txt" in the Resources folder. Is there anything else that I should do? English.txt consists of key = value pairs. Also it was working in 3.4.9 because there we could set all the language files in editor through a public variable of Localization.cs. But now, there is no such list and it can't load the file from Resources.

Thanks.

EDIT: Ok , I found it. I had to delete the file NGUI/Examples/Resources/Localization file to fix it. I think you should put this info to the documentation.
Title: Re: Localization system
Post by: PoN on November 30, 2014, 11:05:30 PM
My Localization.csv first language is not an English. Unity 4.6 , NGUI 3.7.6

KEY,RU,EN
string,string,string
TID_LANGUAGE_RU,Русский,Русский
TID_LANGUAGE_EN,English,English
..
..
..

i got error (see below the attach), could you explain to me , why ?

thanks.
Title: Re: Localization system
Post by: ArenMook on December 02, 2014, 12:32:05 PM
Your keys are strange. It should be:
  1. KEY,RU,EN
  2. TID_LANGUAGE,Русский,English
What's the point of duplicating all that data? The whole point of localization is to translate values. When you localize "TID_LANGUAGE" you will get "Русский" if you're using the Russian language, and "English" if you're using the English language.

Other than that, make sure that you number of columns is the same. You have 3 columns, so all rows must also have 3 columns.
Title: Re: Localization system
Post by: PoN on December 04, 2014, 09:45:58 PM
but Why preview doesn't work anymore ?

Quote
What's the point of duplicating all that data?
So tell me pls , how could i get many values of key ? i need get values for a one key.
Title: Re: Localization system
Post by: ArenMook on December 05, 2014, 01:05:19 AM
I don't understand what you mean.

In my example Localization.Get("TID_LANGUAGE") will return "English" if the Localization.language is set to "EN", or "Русский" if the language is "RU".
Title: Re: Localization system
Post by: kulesz on December 30, 2014, 08:06:00 AM
I got my localization system partially working. But after reading 4 pages of this topic there's still a problem.

A have only one Localization.csv file in the project.
When I add UILocalize component to label I cannot select my keys from the list (red cross on the right). However after manually entering key and running a project the preview field get's filled and it works as expected (while still running). After stopping the game in editor UILocalize "holds" its values for a while / a few clicks and then it disappears again (red cross).
I cannot also change language in runtime. When I do: Localization.language = "French" nothing changes. Labels stay the same, but whats interesting - after disabling and enabling buttons the labels change to 'key' value.
It's seems very random and messy to me... Does anyone know what can cause such problems?
Title: Re: Localization system
Post by: ArenMook on December 30, 2014, 02:00:12 PM
Well first it should be Localization.txt, not .csv and second -- make sure you don't have any other Localization files in your Resources folders. Remember, NGUI comes with one.
Title: Re: Localization system
Post by: kulesz on December 30, 2014, 03:09:10 PM
Thanks, but I still have some issue,
I've changed the file name and there's only one Localization.txt file (double checked). And this is what I'm doing:

[ATTACHMENT SCREEN 1]
[ATTACHMENT SCREEN 2]

Title: Re: Localization system
Post by: kulesz on December 30, 2014, 04:51:34 PM
Got it working :)

It seems that language string that I passed had "\r\n" on the end (which was difficult to spot in inspector).
After removing those everything works fine.
Title: I2 Localization
Post by: JorgeM on January 09, 2015, 06:16:44 AM
Was I2 Localization made by NGUI team?
In case it wasn't, is it as good as NGUI and better than the default NGUI Localization system?
I am considering buying it.
Thank you.
Title: Re: Localization system
Post by: ArenMook on January 10, 2015, 01:13:37 PM
No, it's a third party tool. It expands the localization functionality of NGUI, adding new features. You can find its thread in the general forum: http://www.tasharen.com/forum/index.php?topic=8324.0
Title: Re: Localization system
Post by: emile_d on January 26, 2015, 08:42:57 AM
We're working for a multi-language game now. Is there any method to 'localize' font for UILabel? I mean using different font for every language? (Because a font may not contain all characters for all languages. And we're using dynamic font renderering in Unity.)

What I thought to implement this is to attach a script on all game objects which have UILabel components. The script can change the font of the UILabel according to the current language users selected. Do you have any other better idea?

Thank you!
Title: Re: Localization system
Post by: ArenMook on January 27, 2015, 04:48:04 AM
Yes, reference fonts. Look into that feature. You'll create an empty font prefab set to be a Reference, pointing to an actual font with data in it. All your labels will be using this Reference Font prefab. When loading your game, Resources.Load the appropriate font with data in it and set the reference font's value to point to it, thus automatically making your labels use the newly loaded font.
Title: Re: Localization system
Post by: emile_d on January 27, 2015, 07:47:58 AM
Yes, reference fonts. Look into that feature. You'll create an empty font prefab set to be a Reference, pointing to an actual font with data in it. All your labels will be using this Reference Font prefab. When loading your game, Resources.Load the appropriate font with data in it and set the reference font's value to point to it, thus automatically making your labels use the newly loaded font.

Yes! It works. It recalls me that UIAtlas also has the reference function. Thank you for the support and this handy GUI kit.
Title: Re: Localization system
Post by: NaxIonz on May 02, 2016, 06:14:25 PM
What workflow to you recommend for doing:

  1. string.Format("Example {0}, {1}", param_a, param_b);

Would you do something like:

  1. label.text = string.Format(label.text, param_a, param_b);

or

  1. label.text = string.Format(Localization.Get(key), param_a, param_b);
Title: Re: Localization system
Post by: ArenMook on May 03, 2016, 01:50:37 PM
  1. label.text = Localization.Format(key, param_a, param_b);
Title: Re: Localization system
Post by: hollym16 on June 07, 2016, 05:37:13 AM
Hi, I've been using your system to add multiple languages to my App. Thus far it has been the user selecting a language via a button.
However, is there a way to detect the current language the device is set to and apply that to the App?
Many Thanks
Title: Re: Localization system
Post by: ArenMook on June 09, 2016, 02:51:56 PM
You can change the Localization.language at any time, such as in a script's Start() function when your app loads up.
Title: Re: Localization system
Post by: hollym16 on June 16, 2016, 07:00:23 AM
Hi,
Is there a way of linking specific audio files to the localised text?
For example, two different audio files are available, one a voice over in English, another a voice over in German.
If English is the selected language, then the English voice over plays.
Is there a way of incorporating it into the CSV file? I need to do this with a number of scenes
Title: Re: Localization system
Post by: ArenMook on June 18, 2016, 05:11:58 AM
CSV file is just text. You can only put text in there -- such as the name of your audio file. Then create a script similar to UILocalize that would have an OnLocalize function and would do a
  1. GetComponent<AudioSource>().clip = Resources.Load<AudioClip>(Localization.Get(key));
Title: Re: Localization system
Post by: hollym16 on June 20, 2016, 09:39:52 AM
Would I have to create a CSV file separate from my current one that changes text?
I tried to change the TextLocalize script to specify audio rather than text but I get errors saying 'Cannot implicitly convert type `string' to `UnityEngine.AudioClip'
Sorry, I'm not familiar with such complex coding, could you please explain a little more please?
Title: Re: Localization system
Post by: ArenMook on June 24, 2016, 01:50:51 AM
I posted you the code you need that loads the clip and converts it from text, assigning it to your audio source... Literally everything you need is that one line.