Author Topic: localization support for csv file?  (Read 10286 times)

serioustommy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
localization support for csv file?
« on: May 29, 2012, 05:43:36 AM »
I thought spreadsheet is a convenient way for working with localized strings. Since csv is one of the default output from google doc wouldn't it be nice to have NGUI parse that directly? I know it's easy to just replace all the "," with "=" but when you have 6 languages and multiple changes a day it does get a bit tedious.

Or perhaps I just need to look into how to write a google plugin that outputs the correct format...

PhilipC

  • Guest
Re: localization support for csv file?
« Reply #1 on: May 29, 2012, 08:56:15 AM »
You could always change how NGUI parses the data file that is being read instead of writing a google doc. In Localization.Load(TextAsset) replace the "mDictionary = reader.ReadDictionary()" with how every you wanted the file parsed. The current example will continue to parse the = separator but you can add to that list or replace it with just ','.

  1. mDictionary.Clear();
  2. while(reader.canRead)
  3. {
  4.         string line = reader.ReadLine();
  5.         char[] separators = new char[] {'='};
  6.         string[] kvp = line.Split(separators, 2);
  7.        
  8.         if (kvp.Length != 2)
  9.         {
  10.                 Debug.Log("Error parsing line " + line + "  " + kvp.Length);
  11.                 continue;
  12.         }
  13.        
  14.         mDictionary.Add(kvp[0].Trim(), kvp[1].Trim());                 
  15. }
  16.  
« Last Edit: May 29, 2012, 09:08:21 AM by PhilipC »

serioustommy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: localization support for csv file?
« Reply #2 on: May 29, 2012, 09:09:54 AM »
Well I could also easily change the separator in ReadDictionary from "=" to "," but I'd rather not break compatibility to NGUI from future updates with little changes here and there. Maybe we need a simple pluggable reader that we can inject into NGUI for custom formats?

PhilipC

  • Guest
Re: localization support for csv file?
« Reply #3 on: May 29, 2012, 09:17:02 AM »
You have two options using the method i suggested

One would be
  1.  char[] separators = new char[] {','};

The other would be
  1.  char[] separators = new char[] {'=', ','};

The second way would keep NGUI's current functionality of reading '=' as separators as well as adding the possibility of having ',' as a separator

serioustommy

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: localization support for csv file?
« Reply #4 on: May 29, 2012, 09:53:09 AM »
I would really rather not make changes to NGUI classes, just to avoid future headaches when updating. Imagine having to keep track of 10 little changes like this and having to double check them to see if they are overwritten by NGUI's update every time.

Maybe the next update can include your second change so that it supports both? Thanks for the suggestion though.

ranilian

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 24
    • View Profile
    • Industry Corporation
Re: localization support for csv file?
« Reply #5 on: May 29, 2012, 10:14:55 AM »
It would be easy to add it as a public variable that defaults to '=' and allows anyone to change it in the editor.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: localization support for csv file?
« Reply #6 on: May 29, 2012, 02:19:37 PM »
NGUI's code is exposed precisely so that you can change it to suit the needs of your project.

soulis6

  • Guest
Re: localization support for csv file?
« Reply #7 on: October 19, 2012, 01:56:16 PM »
This is the question i came in here to ask, and it works great for other characters, but what if you wanted the pair to be separated by lines instead?
So instead of:

Key = Translation

it would be

Key
Translation

What would you recommend for that? I dont' know enough about text parsing to figure it out just from looking at the code

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: localization support for csv file?
« Reply #8 on: October 19, 2012, 02:47:59 PM »
I wouldn't recommend it as it becomes more difficult to tell which line is what -- is it a key? is it a value? Someone is bound to insert a new line character somewhere eventually, throwing everything off.