예제 #1
0
        private static LocalizationInfo GetLocalizationInfo(PropertyInfo prop)
        {
            var attr = prop.GetCustomAttribute <LocalizeAttribute>();

            if (attr == null)
            {
                return(null);
            }
            var info = new LocalizationInfo
            {
                ResourceName = attr.ResourceName ?? (prop.DeclaringType.Name + "_" + prop.Name)
            };

            if (info.ResourceType != null)
            {
                info.ResourceType = attr.ResourceType;
            }
            else
            {
                var parent = prop.DeclaringType.GetTypeInfo().GetCustomAttribute <LocalizeAttribute>();
                if (parent == null || parent.ResourceType == null)
                {
                    throw new ArgumentException(String.Format(
                                                    "The property '{0}' or its parent class '{1}' must define a ResourceType in order to be localized.",
                                                    prop.Name, prop.DeclaringType.Name));
                }
                info.ResourceType = parent.ResourceType;
            }

            return(info);
        }
        public SettingsLanguageViewModel()
        {
            _localizations = CollectionViewSource.GetDefaultView(LocalizationManager.List);
            _localizations.SortDescriptions.Add(new SortDescription(nameof(LocalizationInfo.Name), ListSortDirection.Ascending));

            _localizations.Filter = o =>
            {
                if (string.IsNullOrEmpty(Search))
                {
                    return(true);
                }

                LocalizationInfo info = o as LocalizationInfo;

                string search = Search.Trim();

                // Search by: Name
                return(info.Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1 || info.NativeName.IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1);
            };

            LocalizationSelectedItem = Localizations.Cast <LocalizationInfo>().FirstOrDefault(x => x.Code == LocalizationManager.Current.Code);

            LoadSettings();

            _isLoading = false;
        }
예제 #3
0
    /// <summary>
    /// 读语言包(读的是localizationTable)
    /// </summary>
    /// <param name="wordId">Word identifier.</param>
    public static string UIWord(int wordId)
    {
        LocalizationInfo lan = ResManager.Instance.localizationTable.GetById(wordId);

        if (lan != null && lan.localizedText != null)
        {
            return(lan.localizedText.Replace("\\n", "\n"));
        }
        return("");
    }
예제 #4
0
 public SettingsYaml(bool gameUpdates, bool gameCheckServer, LocalizationInfo localizationInfo, EncodedString gameJoltUsername, EncodedString gameJoltToken, bool autoLogIn, bool saveCredentials)
 {
     GameUpdates      = gameUpdates;
     GameCheckServer  = gameCheckServer;
     LocalizationInfo = localizationInfo;
     GameJoltUsername = gameJoltUsername;
     GameJoltToken    = gameJoltToken;
     AutoLogIn        = autoLogIn;
     SaveCredentials  = saveCredentials;
 }
예제 #5
0
        public Localization(LocalizationInfo localizationInfo, IFolder translationsFolder = null)
        {
            if (translationsFolder == null)
            {
                TranslationsFolder = new TranslationsFolder(new MainFolder().CreateFolder("Translation", CreationCollisionOption.OpenIfExists));
            }
            else
            {
                TranslationsFolder = new TranslationsFolder(translationsFolder);
            }

            LoadTranslationFiles(TranslationsFolder.GetTranslationFolder(localizationInfo));
        }
예제 #6
0
    void OnGUI()
    {
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false);

        GUILayout.BeginHorizontal();

        GUILayout.BeginVertical();
        EditorGUILayout.LabelField("Buttons", EditorStyles.boldLabel);

        foreach (Text t in myTextList)
        {
            EditorGUILayout.LabelField(t.gameObject.name);
        }

        GUILayout.EndVertical();

        foreach (string s in TextManager.availableLanguages)
        {
            GUILayout.BeginVertical();

            EditorGUILayout.LabelField(s, EditorStyles.boldLabel);

            EditorGUILayout.Space();

            foreach (Text t in myTextList)
            {
                LocalizationInfo lI = t.gameObject.GetComponent <LocalizationInfo> ();

                if (!lI.traductionDico.ContainsKey(s))
                {
                    lI.traductionDico.Add(s, t.text);
                }

                lI.traductionDico[s] = EditorGUILayout.TextField(lI.traductionDico[s]);
            }

            GUILayout.EndVertical();
        }

        GUILayout.EndHorizontal();

        EditorGUILayout.EndScrollView();

        GUILayout.FlexibleSpace();

        if (GUILayout.Button("Save"))
        {
            Save();
        }
    }
예제 #7
0
 public bool CheckTranslationExists(LocalizationInfo localizationInfo)
 {
     return(GetTranslationFolders().Any(file =>
     {
         if (Equals(file.LocalizationInfo.CultureInfo, localizationInfo.CultureInfo))
         {
             if (!string.IsNullOrEmpty(localizationInfo.SubLanguage) && !string.IsNullOrEmpty(file.LocalizationInfo.SubLanguage))
             {
                 return Equals(file.LocalizationInfo.SubLanguage, localizationInfo.SubLanguage);
             }
             return true;
         }
         return Equals(file.LocalizationInfo.CultureInfo, localizationInfo.CultureInfo);
     }));
 }
예제 #8
0
 public async Task <bool> CheckTranslationExistsAsync(LocalizationInfo localizationInfo, CancellationToken cancellationToken = default(CancellationToken))
 {
     return((await GetTranslationFoldersAsync(cancellationToken)).Any(file =>
     {
         if (Equals(file.LocalizationInfo.CultureInfo, localizationInfo.CultureInfo))
         {
             if (!string.IsNullOrEmpty(localizationInfo.SubLanguage) && !string.IsNullOrEmpty(file.LocalizationInfo.SubLanguage))
             {
                 return Equals(file.LocalizationInfo.SubLanguage, localizationInfo.SubLanguage);
             }
             return true;
         }
         return Equals(file.LocalizationInfo.CultureInfo, localizationInfo.CultureInfo);
     }));
 }
예제 #9
0
        private static LocalizationInfo GetLocalizationInfo(Type type)
        {
            var attr = type.GetTypeInfo().GetCustomAttribute <LocalizeAttribute>();

            if (attr == null || attr.ResourceType == null)
            {
                throw new ArgumentException(String.Format(
                                                "The class '{0}' must define a ResourceType in order to be localized.",
                                                type.Name));
            }
            var info = new LocalizationInfo
            {
                ResourceType = attr.ResourceType,
                ResourceName = attr.ResourceName ?? type.Name
            };

            return(info);
        }
예제 #10
0
        public void Execute(LocalizationInfo localization)
        {
            // Try to switch to the next available localization
            if (localization == null && Translator.AvailableLocalizations.Count() > 0)
            {
                bool foundCurrentCulture = false;

                foreach (LocalizationInfo localizationInfo in Translator.AvailableLocalizations)
                {
                    // Any available if fine for case, when only default fallback localization is currently used
                    if (Translator.CurrentLocalization == null)
                    {
                        Translator.CurrentLocalization = localizationInfo;
                        break;
                    }

                    // Setting next localization from available
                    if (foundCurrentCulture)
                    {
                        Translator.CurrentLocalization = localizationInfo;
                        foundCurrentCulture            = false;
                        break;
                    }

                    // Current localization is found and next iteration
                    // will be used to apply next localization from available
                    if (Translator.CurrentLocalization.FileName == localizationInfo.FileName)
                    {
                        foundCurrentCulture = true;
                    }
                }

                // current localization was last in the available list, so starting from first available
                if (foundCurrentCulture)
                {
                    Translator.CurrentLocalization = Translator.AvailableLocalizations.First();
                }
            }
            else
            {
                // Set specific localization
                Translator.CurrentLocalization = localization;
            }
        }
예제 #11
0
    void Load()
    {
        foreach (Text t in myTextList)
        {
            LocalizationInfo lI = t.gameObject.GetComponent <LocalizationInfo> ();

            if (!lI)
            {
                lI = t.gameObject.AddComponent <LocalizationInfo> ();
            }

            if (lI.traductionDico == null)
            {
                lI.traductionDico = new Dictionary <string, string>();
            }

            lI.InitDico();
        }
    }
예제 #12
0
    public static void ChangeTrad(Languages l)
    {
        string languageName = languagesNames [l];

        /*foreach (TranslationObject tO in TextManager.texts.translations) {
         *      if (tO.language == languageName) {
         *              TextManager.texts.currentTranslation = tO;
         *      }
         * }*/

        foreach (Text t in Resources.FindObjectsOfTypeAll(typeof(Text)))
        {
            LocalizationInfo lI = t.GetComponent <LocalizationInfo> ();

            if (lI && !lI.ignoreThis)
            {
                //Debug.Log (t.name + " " + t.text);

                t.text = lI.traductionDico [languageName];
            }
        }
    }
예제 #13
0
    void Save()
    {
        foreach (Text t in myTextList)
        {
            LocalizationInfo lI = t.gameObject.GetComponent <LocalizationInfo> ();

            lI.traductions = new List <LocalizationInfo.Traduction> ();

            foreach (KeyValuePair <string, string> trad in lI.traductionDico)
            {
                LocalizationInfo.Traduction myTrad = new LocalizationInfo.Traduction();

                myTrad.language   = trad.Key;
                myTrad.traduction = trad.Value;

                lI.traductions.Add(myTrad);
            }
        }

        GameObject go = GameObject.FindGameObjectWithTag("MainCanvas");

        PrefabUtility.ReplacePrefab(go, PrefabUtility.GetPrefabParent(go), ReplacePrefabOptions.ConnectToPrefab);
    }
예제 #14
0
        /// <summary>
        /// Initialize current translation and all other available languages.
        /// </summary>
        private static void InitCulture()
        {
            // TODO: make languages folder configuragle
            Translator.LocalizationProvider = new XmlFileLocalizationProvider
            {
                Folder = DefaultLocalizationFolder
            };

            Translator.RefreshAvailableLocalizations();

            if (Translator.AvailableLocalizations.Count() > 0)
            {
                // prefer natural UI culture
                LocalizationInfo uiCulture = (from info in Translator.AvailableLocalizations
                                              where info.Culture.LCID == Translator.CurrentUICulture.LCID
                                              select info).FirstOrDefault();

                // next try culture from region settings
                LocalizationInfo culture = (from info in Translator.AvailableLocalizations
                                            where info.Culture.LCID == Translator.CurrentCulture.LCID
                                            select info).FirstOrDefault();

                // next try "DefaultCulture" (for example, with custom translation)
                // TODO: make default culture resource string
                LocalizationInfo englishCulture = (from info in Translator.AvailableLocalizations
                                                   where info.Culture.LCID == Translator.DefaultCulture.LCID
                                                   select info).FirstOrDefault();

                Translator.CurrentLocalization = uiCulture ?? culture ?? englishCulture;
            }
            else
            {
                // set fallback culture
                Translator.CurrentLocalization = null;
            }
        }
예제 #15
0
        private static void LoadTokenFile(LocalizationsFolder localizationsFolder, bool isGameModeFile)
        {
            var defaultLanguage  = new CultureInfo("en");
            var localizationInfo = new LocalizationInfo(Language);

            if (!localizationsFolder.CheckTranslationExists(localizationInfo))
            {
                Language = defaultLanguage;
            }

            LocalizationFiles.AddRange(localizationsFolder.GetTranslationFolder(localizationInfo).GetTranslationFiles().ToList());
            if (!Equals(Language, defaultLanguage))
            {
                LocalizationFiles.AddRange(localizationsFolder.GetTranslationFolder(new LocalizationInfo(defaultLanguage)).GetTranslationFiles().ToList());
            }


            /*
             * {
             *  foreach (var tokenLine in localizationsFolder.GetTranslationFolder(localizationInfo).GetTranslationFile(Language).ReadAllLines())
             *  {
             *      if (tokenLine.Contains(","))
             *      {
             *          var splitIdx = tokenLine.IndexOf(",", StringComparison.Ordinal);
             *
             *          var tokenName = tokenLine.Substring(0, splitIdx);
             *          var tokenContent = "";
             *          if (tokenLine.Length > tokenName.Length + 1)
             *              tokenContent = tokenLine.Substring(splitIdx + 1, tokenLine.Length - splitIdx - 1);
             *
             *          if (!LocalizationTokens.ContainsKey(tokenName))
             *              LocalizationTokens.Add(tokenName,
             *                  new Token(tokenName, tokenContent, Language, isGameModeFile));
             *      }
             *  }
             * }
             *
             *
             *
             * // -- Load default definitions, the current language may not have everything translated
             * if (!Equals(Language, defaultLanguage))
             * {
             *  if (localizationFolder.CheckTranslationExists(defaultLanguage))
             *  {
             *      foreach (var tokenLine in localizationFolder.GetTranslationFile(defaultLanguage).ReadAllLines())
             *      {
             *          if (tokenLine.Contains(","))
             *          {
             *              var splitIdx = tokenLine.IndexOf(",", StringComparison.Ordinal);
             *
             *              var tokenName = tokenLine.Substring(0, splitIdx);
             *              var tokenContent = "";
             *              if (tokenLine.Length > tokenName.Length + 1)
             *                  tokenContent = tokenLine.Substring(splitIdx + 1, tokenLine.Length - splitIdx - 1);
             *
             *              if (!LocalizationTokens.ContainsKey(tokenName))
             *                  LocalizationTokens.Add(tokenName, new Token(tokenName, tokenContent, defaultLanguage, isGameModeFile));
             *          }
             *      }
             *  }
             * }
             */
        }
 public static void Load(LocalizationInfo localizationInfo) => Localization = new Localization(localizationInfo);
예제 #17
0
 /// <summary>
 /// Check if the localization is valid to be applied.
 /// </summary>
 /// <param name="localization">New localization.</param>
 /// <returns>True, if localization can be applied.</returns>
 public bool CanExecute(LocalizationInfo localization)
 {
     return(true);
 }
예제 #18
0
 public async Task <TranslationFolder> GetTranslationFolderAsync(LocalizationInfo localizationInfo, CancellationToken cancellationToken = default(CancellationToken)) => (await GetTranslationFoldersAsync(cancellationToken)).FirstOrDefault(folder => localizationInfo.Equals(folder.LocalizationInfo));
 public TranslationFolder(IFolder folder, LocalizationInfo localizationInfo) : base(folder)
 {
     LocalizationInfo = localizationInfo;
 }
예제 #20
0
 public TranslationFolder GetTranslationFolder(LocalizationInfo localizationInfo) => GetTranslationFolders().FirstOrDefault(folder => localizationInfo.Equals(folder.LocalizationInfo));
 private void LoadSettings()
 {
     LanguageCollection       = new ObservableCollection <LocalizationInfo>(LocalizationManager.List);
     LocalizationSelectedItem = LanguageCollection.FirstOrDefault(x => x.Code == LocalizationManager.Current.Code);
 }