Author Topic: Localization system  (Read 50389 times)

syslord2k2

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Localization system
« Reply #15 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

dt1000

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Localization system
« Reply #16 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: Localization system
« Reply #17 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.

dt1000

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Localization system
« Reply #18 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...
 :-[

luvcraft

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 11
    • View Profile
Re: Localization system
« Reply #19 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: Localization system
« Reply #20 on: March 21, 2014, 04:13:34 PM »
Thanks, I'll fix it on my end.

dandrea

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 2
  • Posts: 23
    • View Profile
Re: Localization system
« Reply #21 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.

XPEC02

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: Localization system
« Reply #22 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?
« Last Edit: April 03, 2014, 05:24:51 AM by XPEC02 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: Localization system
« Reply #23 on: April 03, 2014, 09:58:21 PM »
Wrap it in quotes.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: Localization system
« Reply #24 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.

Genesia

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Localization system
« Reply #25 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: Localization system
« Reply #26 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.

Genesia

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Localization system
« Reply #27 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.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: Localization system
« Reply #28 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

luizfranca

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Localization system
« Reply #29 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.