Author Topic: Localization feature request  (Read 3335 times)

MrMatthias

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Localization feature request
« on: February 28, 2014, 10:40:26 AM »
Could you add something like this to Localization?
  1.                 public static bool FixLanguage (string language, Func<string, string> fix)
  2.                 {
  3.                                 int index = Array.IndexOf<string> (Localization.knownLanguages, language);
  4.                                 if (index == -1) {
  5.                                                 return false;
  6.                                 }
  7.                                 Dictionary<string, string[]> toFixDict = Localization.dictionary;
  8.                                 Dictionary<string, string> fixedDict = new Dictionary<string, string> ();
  9.                                 foreach (KeyValuePair<string, string[]> entry in toFixDict) {
  10.                                                 fixedDict.Add (entry.Key, fix (entry.Value [index]));
  11.                                 }
  12.                                 Localization.Set (language, fixedDict);
  13.                                 return true;
  14.                 }

So you can apply a fix to a specific language like this:
  1.                                 if (Application.systemLanguage.Equals ("Arabic")) {
  2.                                                 Localization.FixLanguage ("Arabic", x => {
  3.                                                                 return UnityArabicSupport.ArabicFixer.Fix (x);});
  4.                                 }

Automatically switching Left and Right Anchors would be cool too.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Localization feature request
« Reply #1 on: February 28, 2014, 06:09:58 PM »
This seems like highly custom code that won't apply to most users (what's "fix"? how do you define "fixing" something?), and you can do this without having to modify the Localization class. It's best if you kept it local to your project.

MrMatthias

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Localization feature request
« Reply #2 on: February 28, 2014, 07:04:47 PM »
It seems to be required for arabic and persian letters.
See https://www.assetstore.unity3d.com/#/content/2674.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Localization feature request
« Reply #3 on: February 28, 2014, 07:10:53 PM »
Yes, but you don't need to modify the localization class to do what you're trying to do.

That function will work just the same inside your own class rather than being a part of the localization. Now, if you were to add a custom delegate to the localization class that would be called before setting each text, then it would make sense to modify the localization class.

MrMatthias

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Localization feature request
« Reply #4 on: February 28, 2014, 07:35:40 PM »
Iterating through the words based on the position of the language's name in a list of supported languages seems more like a hack. It shouldn't require knowledge of Localization's internal structure.
But i guess i can live with that solution ^^