コード例 #1
0
        private void ApplyChanges()
        {
            _data = new SortedDictionary <string, LocalizationRecord>();
            foreach (var keyValuePair in _mixedData)
            {
                if (keyValuePair.Value.Status != PairStatus.Removed)
                {
                    _data.Add(keyValuePair.Key, keyValuePair.Value);
                }
            }

            var rawData = new List <string[]>();

            foreach (var item in _data)
            {
                item.Value.Status = PairStatus.NoneChanged;

                rawData.Add(new[] {
                    item.Key,
                    I18nService.Screen(string.IsNullOrEmpty(item.Value.Value) ? item.Key + "_Value" : item.Value.Value),
                    I18nService.Screen(item.Value.Hint),
                    item.Value.Source.ToString()
                });
            }

            var source = I18nHelpers.BuildCSV(rawData);

            source = I18nService.UnScreen(source);

            var writer = new StreamWriter(PathToFile, false);

            writer.Write(source);
            writer.Close();

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            RevertChanges();
        }
コード例 #2
0
        private void ProcessSearchResult()
        {
            _mixedData = new SortedDictionary <string, LocalizationRecord>();

            ParseAndUpdateVariables(_foundedData);

            var translationsFromFile = _data;
            var newSearchedKeys      = _foundedData;

            foreach (var fromSavedFile in translationsFromFile)
            {
                var mergeResult = (LocalizationRecord)fromSavedFile.Value.Clone();

                _mixedData.Add(fromSavedFile.Key, mergeResult);

                if (!_searchSource.HasFlag(mergeResult.Source))
                {
                    mergeResult.Status = PairStatus.NoneChanged;
                    continue;
                }

                if (mergeResult.Source.HasFlag(Source.Variable))
                {
                    continue;
                }

                LocalizationRecord foundedLocalizationRecord;
                newSearchedKeys.TryGetValue(fromSavedFile.Key, out foundedLocalizationRecord);

                if (foundedLocalizationRecord != null)
                {
                    if (!_searchSource.HasFlag(foundedLocalizationRecord.Source))
                    {
                        continue;
                    }

                    if (foundedLocalizationRecord.Source == Source.Code || foundedLocalizationRecord.Source == Source.PrefabAndScene)
                    {
                        mergeResult.Source = foundedLocalizationRecord.Source;

                        if (mergeResult.Hint != I18nService.UnScreen(foundedLocalizationRecord.Hint))
                        {
                            mergeResult.Hint   = foundedLocalizationRecord.Hint;
                            mergeResult.Status = PairStatus.Changed;
                            foundedLocalizationRecord.Status = PairStatus.Changed;
                        }
                        continue;
                    }
                    else if (foundedLocalizationRecord.Source == Source.Config)
                    {
                        if (mergeResult.Value != foundedLocalizationRecord.Value || mergeResult.Hint != I18nService.UnScreen(foundedLocalizationRecord.Hint))
                        {
                            mergeResult.Value  = foundedLocalizationRecord.Value;
                            mergeResult.Hint   = foundedLocalizationRecord.Hint;
                            mergeResult.Status = PairStatus.Changed;
                        }
                    }

                    continue;
                }
                mergeResult.Status = PairStatus.Removed;
            }

            foreach (var founded in newSearchedKeys)
            {
                if (founded.Value.Status == PairStatus.Changed)
                {
                    continue;
                }

                if (!_searchSource.HasFlag(founded.Value.Source) && !(founded.Key.StartsWith("$") && founded.Key.EndsWith("_Name")))
                {
                    continue;
                }

                if (!translationsFromFile.ContainsKey(founded.Key))
                {
                    founded.Value.Status = PairStatus.New;
                    _mixedData.Add(founded.Key, founded.Value);
                }
            }
        }