示例#1
0
        public string GetValue(string key, SystemLanguage language, SystemLanguage fallback, out SystemLanguage type)
        {
            List <LanPair> pairs;

            if (!_keyDic.TryGetValue(key, out pairs))
            {
                type = SystemLanguage.Unknown;
                return(null);
            }

            LanPair _fallback = null;

            for (int j = 0; j < pairs.Count; j++)
            {
                var pair = pairs[j];
                if (pair.lan == language)
                {
                    type = this.language;
                    return(pair.value);
                }
                else if (pair.lan == fallback)
                {
                    _fallback = pair;
                }
            }
            if (_fallback == null)
            {
                type = SystemLanguage.Unknown;
                return(null);
            }

            type = fallback;
            return(_fallback.value);
        }
示例#2
0
 public void Publish(SystemLanguage value)
 {
     for (int i = 0; i < _observers.Count; i++)
     {
         var            o = _observers[i];
         List <LanPair> pairs;
         if (!_keyDic.TryGetValue(o.languageKey, out pairs))
         {
             continue;
         }
         LanPair fallback = null;
         bool    ok       = false;
         for (int j = 0; j < pairs.Count; j++)
         {
             var pair = pairs[j];
             if (pair.lan == value)
             {
                 o.Listen(value, pair.value);
                 ok = true;
                 break;
             }
             else if (pair.lan == o.fallbackLanguage)
             {
                 fallback = pair;
             }
         }
         if (!ok && fallback != null)
         {
             o.Listen(o.fallbackLanguage, fallback.value);
         }
     }
 }
示例#3
0
            private string GetValueInPairs()
            {
                LanPair pair = _pairs.Find(p => { return(p.lan == curLan); });

                if (pair == null)
                {
                    pair = _pairs.Find(p => { return(p.lan == fallback); });
                }
                return(pair == null ? string.Empty : pair.value);
            }
示例#4
0
 public void Load(List <LanPair> pairs, bool rewrite = true)
 {
     pairs.ForEach((tmpPair) => {
         LanPair pair = _pairs.Find((p) => { return(p.lan == tmpPair.lan && p.key == tmpPair.key); });
         if (pair != null && rewrite && pair.value != tmpPair.value)
         {
             pair.value = tmpPair.value;
         }
         else
         {
             _pairs.Add(tmpPair);
         }
     });
     pairs.Clear();
     _keyDic = _pairs.GroupBy(lanPair => { return(lanPair.key); }, (key, list) => { return(new { key, list }); })
               .ToDictionary((v) => { return(v.key); }, (v) => { return(v.list.ToList()); });
 }
示例#5
0
        public void Load(ILanPairGroup group, bool reWrite = true)
        {
            List <LanPair> tmpPairs = group.Load();

            tmpPairs.ForEach((tmpPair) => {
                LanPair pair = _lanPairs.Find((p) => { return(p.lan == tmpPair.lan && p.key == tmpPair.key); });
                if (pair != null && reWrite && pair.value != tmpPair.value)
                {
                    pair.value = tmpPair.value;
                }
                else
                {
                    _lanPairs.Add(tmpPair);
                }
            });
            tmpPairs.Clear();
            Fresh();
        }
示例#6
0
 public void DeletePair(LanPair pair)
 {
     pairs.Remove(pair);
 }
示例#7
0
            private void AddLanPairFunc()
            {
                if (window._keys.Count == 0)
                {
                    return;
                }
                Rect rect;

                this.EBeginHorizontal(out rect, Styles.Fold)
                .Foldout(ref createLanPairFlodon, "Create LanPair", true)
                .EEndHorizontal()
                .Pan(() =>
                {
                    if (!createLanPairFlodon)
                    {
                        return;
                    }
                    if (tmpLanPair == null)
                    {
                        tmpLanPair = new LanPair()
                        {
                            key = window._keys[0]
                        }
                    }
                    ;
                    if (hashID == 0)
                    {
                        hashID = "CreateView".GetHashCode();
                    }
                    this.DrawVertical(() =>
                    {
                        this.BeginHorizontal()
                        .Label("Lan", GUILayout.Width(describeWidth))
                        .Pan(() => { tmpLanPair.lan = (SystemLanguage)EditorGUILayout.EnumPopup(tmpLanPair.lan); })
                        .EndHorizontal()
                        .BeginHorizontal()
                        .Label("Key", GUILayout.Width(describeWidth))
                        .Label(tmpLanPair.key)
                        .Label(EditorGUIUtility.IconContent("editicon.sml"), GUILayout.Width(smallBtnSize))
                        .EndHorizontal()
                        .Pan(() => {
                            Rect pos   = GUILayoutUtility.GetLastRect();
                            int ctrlId = GUIUtility.GetControlID(hashID, FocusType.Keyboard, pos);
                            {
                                if (DropdownButton(ctrlId, pos, new GUIContent(string.Format("Key: {0}", tmpLanPair.key))))
                                {
                                    int index = -1;
                                    for (int i = 0; i < window._keys.Count; i++)
                                    {
                                        if (window._keys[i] == tmpLanPair.key)
                                        {
                                            index = i; break;
                                        }
                                    }
                                    SearchablePopup.Show(pos, window._keys.ToArray(), index, (i, str) =>
                                    {
                                        tmpLanPair.key = str;
                                        window.Repaint();
                                    });
                                }
                            }
                        })
                        .BeginHorizontal()
                        .Label("Val", GUILayout.Width(describeWidth))
                        .TextField(ref tmpLanPair.value)
                        .EndHorizontal()
                        .BeginHorizontal()
                        .FlexibleSpace()
                        .Button(() => {
                            //createLanPairFlodon = false;
                            window.AddLanPair(tmpLanPair);
                            //tmpLanPair = null;
                        }, Contents.OK)
                        .EndHorizontal();
                    }, Styles.BG);
                });
            }