public LocalizedString(LanguageTags tag, UnityAction callToSetString = null)
    {
        LanguageTag = tag;
        callToSet   = callToSetString;

        LocalizationManager.RegisterLanguageString(this);
    }
Example #2
0
        ///// <summary>
        ///// Retrieves source code of the check specified by check name.
        ///// This source code can be later compiled into binary assembly by OSLEBot.
        ///// </summary>
        ///// <param name="checkName">Name of the check whose source code needs to be retrieved.</param>
        ///// <returns>Source code string. This should be written into a temporary *.cs file if you want to have OSLEBot compile it.</returns>
        ///// <exception cref="ArgumentOutOfRangeException">Thrown when a check with the specified name is not found.</exception>
        ///// <exception cref="ArgumentException">Thrown when more than 1 check matches the specified name. This indicates data inconsistency.</exception>
        //public string GetCheckSourceCode(string checkName)
        //{
        //    var matches = from check in Checks
        //                  where check.Name == checkName
        //                  select check;
        //    if (matches.Count() == 0)
        //        throw new ArgumentOutOfRangeException("checkName", "The specified check not found");
        //    if (matches.Count() > 1)
        //        throw new ArgumentException("Data inconsistency. Found more than 1 check with the same name.",
        //                                    "checkName");
        //    return matches.Single().SourceCode;
        //}

        /// <summary>
        /// Fills this data set with test (sample) data.
        /// </summary>
        public void FillWithTestData()
        {
            Clear();
            var check1 = Checks.AddChecksRow("FedericaTest.cs", "Test for Federica", "");
            var check2 = Checks.AddChecksRow("Branding.cs", "This is check 2", "");
            var check3 = Checks.AddChecksRow("PseudoLoc.cs", "This is check 3", "");
            var check4 = Checks.AddChecksRow("InvalidLocVer.cs", "This is global check for testing globality detection", "");
            var check5 = Checks.AddChecksRow("EACheck.cs", "This is a check that is global for all languages", "");
            var check6 = Checks.AddChecksRow("WordTemplatesMailMerge.cs", "This is a second check that is global for all languages", "");

            var enUS   = Languages.AddLanguagesRow("en-us");
            var frFR   = Languages.AddLanguagesRow("fr-fr");
            var deDE   = Languages.AddLanguagesRow("de-de");
            var pseudo = Languages.AddLanguagesRow("ja-jp.pseudo");
            var plPL   = Languages.AddLanguagesRow("pl-pl");
            var jaJP   = Languages.AddLanguagesRow("ja-jp");
            var brBR   = Languages.AddLanguagesRow("br-BR");

            var msoProject    = Projects.AddProjectsRow("mso");
            var wordProject   = Projects.AddProjectsRow("word");
            var excelProject  = Projects.AddProjectsRow("excel");
            var accessProject = Projects.AddProjectsRow("access");

            LocGroups.AddLocGroupsRow("main_dll", msoProject);
            LocGroups.AddLocGroupsRow("main_dll", wordProject);
            LocGroups.AddLocGroupsRow("main_dll", excelProject);
            var wordTemplates = LocGroups.AddLocGroupsRow("wordtemplates", wordProject);
            var xlintl        = LocGroups.AddLocGroupsRow("xlintl", excelProject);
            var accintl       = LocGroups.AddLocGroupsRow("acc_intl", accessProject);

            ConfigItems.AddConfigItemsRow(pseudo, check1, wordTemplates);
            ConfigItems.AddConfigItemsRow(pseudo, check1, xlintl);
            ConfigItems.AddConfigItemsRow(plPL, check1, wordTemplates);
            ConfigItems.AddConfigItemsRow(enUS, check2, xlintl);
            ConfigItems.AddConfigItemsRow(frFR, check3, accintl);
            ConfigItems.AddConfigItemsRow(frFR, check2, wordTemplates);

            foreach (var lg in LocGroups)
            {
                ConfigItems.AddConfigItemsRow(plPL, check4, lg);
                ConfigItems.AddConfigItemsRow(brBR, check4, lg);
                ConfigItems.AddConfigItemsRow(jaJP, check1, lg);
            }
            SetCheckGlobalForAllLanguages(check5);
            SetCheckGlobalForAllLanguages(check6);

            var allChecksTag = Tags.AddTagsRow("All checks");

            Checks.ToList().ForEach(check => CheckTags.AddCheckTagsRow(check, allChecksTag));

            var eaLanguagesTag = Tags.AddTagsRow("EA languages");

            Languages.ToList().ForEach(language => LanguageTags.AddLanguageTagsRow(language, eaLanguagesTag));

            var allProjectsTag = Tags.AddTagsRow("All projects");

            Projects.ToList().ForEach(project => ProjectTags.AddProjectTagsRow(project, allProjectsTag));
        }
Example #3
0
 /// <summary>
 /// check if input script and langSys is considered a major language.
 /// </summary>
 /// <returns> true if it is a major language </returns>
 internal static bool Contains(ScriptTags script, LanguageTags langSys)
 {
     for (int i = 0; i < majorLanguages.Length; i++)
     {
         if (script == majorLanguages[i].Script &&
             (langSys == LanguageTags.Default || langSys == majorLanguages[i].LangSys))
         {
             return(true);
         }
     }
     return(false);
 }
        private void InitializeOptions(List <string> availableLocales)
        {
            optionToLocaleMap.Clear();
            for (int i = 0; i < availableLocales.Count; i++)
            {
                optionToLocaleMap.Add(i, availableLocales[i]);
            }

            UIComponent.ClearOptions();
            UIComponent.AddOptions(availableLocales.Select(l => LanguageTags.GetLanguageByTag(l)).ToList());
            UIComponent.value = availableLocales.IndexOf(localizationManager.SelectedLocale);
            UIComponent.RefreshShownValue();
        }
Example #5
0
        /// <summary>
        /// Adds an association between the specified tag name and all of the specified languages.
        /// Makes sure the tag exists (creates it if it doesn't exist)
        /// </summary>
        /// <param name="tag">Tag to be applied to languages</param>
        /// <param name="languages">Collection of languages to apply the tag to.</param>
        public void ApplyTagToLanguages(string tag, IEnumerable <string> languages)
        {
            AddMissingTags(new[] { tag });
            var tagRow = Tags.Single(r => r.Tag.Equals(tag));

            foreach (var language in languages)
            {
                var languageRow = Languages.Single(l => l.Name.Equals(language));
                if (LanguageTags.Any(row => row.TagID == tagRow.ID && row.LanguageID == languageRow.ID))
                {
                    continue;
                }
                LanguageTags.AddLanguageTagsRow(languageRow, tagRow);
            }
        }
    public static string GetTextForTag(LanguageTags tag)
    {
        if (m_loadedLanguageFile is null)
        {
            return("");
        }

        string returnText = m_loadedLanguageFile.GetEntryText(tag.ToString());

        if (string.IsNullOrEmpty(returnText))
        {
            return("[" + tag.ToString() + "]");
        }
        return(returnText);
    }
Example #7
0
        /// <summary>
        /// Removes the specified tag from the selected langauge elements of enlistment.
        /// </summary>
        /// <param name="tag">Tag to be revoved from languages.</param>
        /// <param name="languages">List of languages to remove the tag from.</param>
        public void RemoveTagFomLanguages(string tag, IEnumerable <string> languages)
        {
            var tagID = Tags.Single(r => r.Tag.Equals(tag)).ID;

            foreach (var language in languages)
            {
                var languageID = Languages.Single(l => l.Name.Equals(language)).ID;
                var candidates = LanguageTags.Where(x => x.TagID == tagID && x.LanguageID == languageID).ToList();
                if (candidates.Count != 1)
                {
                    continue;                        //Skip, in case the caller requested removal from a language that doesn't have this tag.
                }
                var lt = candidates.Single();
                LanguageTags.RemoveLanguageTagsRow(lt);
            }
        }
Example #8
0
        /// <summary>
        /// API to query the SLDR for an LDML file and save it locally in the SLDR cache and specified directories
        /// </summary>
        /// <param name="destinationPath">Destination path to save the requested LDML file</param>
        /// <param name="languageTag">Current IETF language tag</param>
        /// <param name="topLevelElements">List of top level element names to request. SLDR will always publish identity, so it doesn't need to be requested.
        /// If null, the entire LDML file will be requested.</param>
        /// <param name="filename">Saved filename</param>
        /// <returns>Enum status SldrStatus if file could be retrieved and the source</returns>
        public static SldrStatus GetLdmlFile(string destinationPath, string languageTag, IEnumerable <string> topLevelElements, out string filename)
        {
            CheckInitialized();

            if (String.IsNullOrEmpty(destinationPath))
            {
                throw new ArgumentException("destinationPath");
            }
            if (!Directory.Exists(destinationPath))
            {
                throw new DirectoryNotFoundException("destinationPath");
            }
            if (String.IsNullOrEmpty(languageTag) || (!IetfLanguageTag.IsValid(languageTag)))
            {
                throw new ArgumentException("ietfLanguageTag");
            }
            if (topLevelElements == null)
            {
                throw new ArgumentNullException("topLevelElements");
            }

            string sldrLanguageTag = IetfLanguageTag.Canonicalize(languageTag);
            SldrLanguageTagInfo langTagInfo;

            if (LanguageTags.TryGet(sldrLanguageTag, out langTagInfo))
            {
                sldrLanguageTag = langTagInfo.SldrLanguageTag;
            }
            string[] topLevelElementsArray = topLevelElements.ToArray();

            using (_sldrCacheMutex.Lock())
            {
                var status = SldrStatus.NotFound;
                CreateSldrCacheDirectory();
                string sldrCacheFilePath;
                bool   redirected;
                do
                {
                    string revid, uid = "", tempString;
                    if (destinationPath == SldrCachePath)
                    {
                        filename = string.Format("{0}.{1}", sldrLanguageTag, LdmlExtension);
                    }
                    else
                    {
                        filename = string.Format("{0}.{1}", languageTag, LdmlExtension);
                        // Check if LDML file already exists in destination and read revid and uid
                        if (!ReadSilIdentity(Path.Combine(destinationPath, filename), out tempString, out uid))
                        {
                            uid = DefaultUserId;
                        }
                    }

                    // If languageTag contains fonipa, don't bother trying to access the SLDR
                    if (sldrLanguageTag.Contains(WellKnownSubtags.IpaVariant) || sldrLanguageTag.Contains(WellKnownSubtags.AudioScript))
                    {
                        return(SldrStatus.NotFound);
                    }

                    sldrCacheFilePath = Path.Combine(SldrCachePath, !string.IsNullOrEmpty(uid) && uid != DefaultUserId ? string.Format("{0}-{1}.{2}", sldrLanguageTag, uid, LdmlExtension)
                                                : string.Format("{0}.{1}", sldrLanguageTag, LdmlExtension));
                    // Read revid from cache file
                    ReadSilIdentity(sldrCacheFilePath, out revid, out tempString);

                    // Concatenate parameters for url string
                    string requestedElements = string.Empty;
                    if (topLevelElementsArray.Length > 0)
                    {
                        requestedElements = string.Format("&inc[]={0}", string.Join("&inc[]=", topLevelElementsArray));
                    }
                    string requestedUserId = !string.IsNullOrEmpty(uid) ? string.Format("&uid={0}", uid) : string.Empty;
                    string requestedRevid  = !string.IsNullOrEmpty(revid) ? string.Format("&revid={0}", revid) : string.Empty;
                    string url             = string.Format("{0}{1}?ext={2}&flatten=1{3}{4}{5}",
                                                           SldrRepository, sldrLanguageTag, LdmlExtension,
                                                           requestedElements, requestedUserId, requestedRevid);

                    string tempFilePath = sldrCacheFilePath + "." + TmpExtension;

                    // Using WebRequest instead of WebClient so we have access to disable AllowAutoRedirect
                    var webRequest = (HttpWebRequest)WebRequest.Create(Uri.EscapeUriString(url));
                    webRequest.AllowAutoRedirect = false;
                    webRequest.UserAgent         = UserAgent;
                    webRequest.Timeout           = 10000;

                    try
                    {
                        if (_offlineMode)
                        {
                            throw new WebException("Test mode: SLDR offline so accessing cache", WebExceptionStatus.ConnectFailure);
                        }

                        // Check the response header to see if the requested LDML file got redirected
                        using (var webResponse = (HttpWebResponse)webRequest.GetResponse())
                        {
                            if (webResponse.StatusCode == HttpStatusCode.NotModified)
                            {
                                // Report status that file is the most current from SLDR
                                status     = SldrStatus.FromSldr;
                                redirected = false;
                            }
                            else if (webResponse.StatusCode == HttpStatusCode.MovedPermanently)
                            {
                                // Extract ietfLanguageTag from the response header
                                var parsedresponse = HttpUtilityFromMono.ParseQueryString(webResponse.Headers["Location"]);
                                sldrLanguageTag = parsedresponse.Get("ws_id").Split('?')[0];
                                redirected      = true;
                            }
                            else
                            {
                                // Download the LDML file to a temp file in case the transfer gets interrupted
                                using (Stream responseStream = webResponse.GetResponseStream())
                                    using (var fs = new FileStream(tempFilePath, FileMode.OpenOrCreate, FileAccess.Write))
                                    {
                                        var buff = new byte[102400];
                                        int c;
                                        while ((c = responseStream.Read(buff, 0, buff.Length)) > 0)
                                        {
                                            fs.Write(buff, 0, c);
                                            fs.Flush();
                                        }
                                    }

                                status            = SldrStatus.FromSldr;
                                sldrCacheFilePath = MoveTmpToCache(tempFilePath, uid);
                                redirected        = false;
                            }
                        }
                    }
                    catch (WebException we)
                    {
                        // Return from 404 error
                        var errorResponse = (HttpWebResponse)we.Response;
                        if ((we.Status == WebExceptionStatus.ProtocolError) && (errorResponse.StatusCode == HttpStatusCode.NotFound))
                        {
                            return(SldrStatus.NotFound);
                        }

                        string sldrCacheFilename;
                        // Download failed so check SLDR cache
                        if (!string.IsNullOrEmpty(uid) && (uid != DefaultUserId))
                        {
                            sldrCacheFilename = string.Format("{0}-{1}.{2}", sldrLanguageTag, uid, LdmlExtension);
                        }
                        else
                        {
                            sldrCacheFilename = string.Format("{0}.{1}", sldrLanguageTag, LdmlExtension);
                        }
                        sldrCacheFilePath = Path.Combine(SldrCachePath, sldrCacheFilename);
                        if (File.Exists(sldrCacheFilePath))
                        {
                            status = SldrStatus.FromCache;
                        }
                        else
                        {
                            return(SldrStatus.UnableToConnectToSldr);
                        }
                        redirected = false;
                    }
                    finally
                    {
                        if (File.Exists(tempFilePath))
                        {
                            File.Delete(tempFilePath);
                        }
                    }
                } while (redirected);

                if (destinationPath != SldrCachePath)
                {
                    // Copy from Cache to destination (w/o uid in filename), overwriting whatever used to be there
                    File.Copy(sldrCacheFilePath, Path.Combine(destinationPath, filename), true);
                }

                return(status);
            }
        }
    // Draw the property inside the given rect
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (Enum.GetNames(typeof(LanguageTags)).Length > 1)
        {
            LanguageTags propertyTag = (LanguageTags)property.FindPropertyRelative("LanguageTag").intValue;

            Rect labelRect = position;
            labelRect.height = 15f;
            EditorGUI.LabelField(labelRect, "Localized String Tag");

            //Alle Categories finden
            categories.Clear();
            foreach (string s in Enum.GetNames(typeof(LanguageTags)))
            {
                if (s != LanguageTags.None.ToString())
                {
                    if (!categories.Contains(s.Split('_')[0]))
                    {
                        categories.Add(s.Split('_')[0]);
                    }
                }
                else
                {
                    categories.Add("None");
                }
            }
            if (propertyTag != LanguageTags.None && Enum.IsDefined(typeof(LanguageTags), propertyTag))
            {
                catIndex = categories.IndexOf(propertyTag.ToString().Split('_')[0]);
            }

            if (catIndex >= categories.Count || catIndex < 0)
            {
                catIndex = 0;
            }

            Rect categoryRect = position;
            categoryRect.x    += 10f;
            categoryRect.y    += 16f;
            categoryRect.width = position.width / 2 - 10 + 5;
            int lastCatIndex = catIndex;
            catIndex = EditorGUI.Popup(categoryRect, catIndex, categories.ToArray());
            if (lastCatIndex != catIndex)
            {
                tagsIndex = 0;
            }

            //Alle tags zur ausgewählten Category finden
            tags.Clear();
            foreach (string s in Enum.GetNames(typeof(LanguageTags)))
            {
                if (s != LanguageTags.None.ToString())
                {
                    //Nur tags zeigen, die die selbe category haben
                    if (s.Split('_')[0] == categories[catIndex])
                    {
                        if (!tags.Contains(s.Split('_')[1]))
                        {
                            tags.Add(s.Split('_')[1]);
                        }
                    }
                }
                else
                {
                    tags.Add("None");
                }
            }

            if (propertyTag != LanguageTags.None && Enum.IsDefined(typeof(LanguageTags), propertyTag))
            {
                tagsIndex = tags.IndexOf(propertyTag.ToString().Split('_')[1]);
            }

            if (tagsIndex >= tags.Count || tagsIndex < 0)
            {
                tagsIndex = 0;
            }

            Rect tagsRect = position;
            tagsRect.x    += position.width / 2 + 5;
            tagsRect.y    += 16f;
            tagsRect.width = position.width / 2 - 5;
            tagsIndex      = EditorGUI.Popup(tagsRect, tagsIndex, tags.ToArray());


            //Wenn gesetzt, die property ändern
            if (Enum.IsDefined(typeof(LanguageTags), (categories[catIndex] + "_" + tags[tagsIndex])))
            {
                property.FindPropertyRelative("LanguageTag").intValue = (int)Enum.Parse(typeof(LanguageTags), (categories[catIndex] + "_" + tags[tagsIndex]));
            }
            else
            {
                property.FindPropertyRelative("LanguageTag").intValue = (int)LanguageTags.None;
            }
        }
        else
        {
            EditorGUI.LabelField(position, "No tags available.");
            property.FindPropertyRelative("LanguageTag").intValue = (int)LanguageTags.None;
        }
    }
Example #10
0
 internal MajorLanguageDesc(CultureInfo culture, ScriptTags script, LanguageTags langSys)
 {
     Culture = culture;
     Script  = script;
     LangSys = langSys;
 }