Esempio n. 1
0
 private string GetCurrentAlternateFileName(string file)
 {
     return(Path.GetDirectoryName(file) +
            Path.DirectorySeparatorChar +
            Path.GetFileNameWithoutExtension(file) + ((!CultureName.IsNullOrEmpty()) ? "." : "") +
            CultureName + Path.GetExtension(file));
 }
Esempio n. 2
0
        public static string GetLang()
        {
            CultureName current = CultureHelper.GetCurrent();
            string      str     = "";

            switch (current)
            {
            case CultureName.EN:
                str = "en";
                break;

            case CultureName.RU:
                str = "ru";
                break;

            case CultureName.UK:
                str = "ua";
                break;

            case CultureName.BE:
                str = "be";
                break;

            case CultureName.PT:
                str = "pt";
                break;

            case CultureName.KZ:
                str = "kz";
                break;
            }
            return(str);
        }
Esempio n. 3
0
 public override int GetHashCode()
 {
     return
         (DataScopeName.GetHashCode() ^
          CultureName.GetHashCode() ^
          TableName.GetHashCode());
 }
 public static GameCulture FromCultureName(CultureName name)
 {
     if (!_NamedCultures.ContainsKey(name))
     {
         return(DefaultCulture);
     }
     return(_NamedCultures[name]);
 }
Esempio n. 5
0
        ////////////////////////////////////////////////////////////////////////
        //
        //  Equals
        //
        //  Implements Object.Equals().  Returns a boolean indicating whether
        //  or not object refers to the same CultureInfo as the current instance.
        //
        ////////////////////////////////////////////////////////////////////////
        public override bool Equals(object obj)
        {
            if (obj is TextInfo that)
            {
                return(CultureName.Equals(that.CultureName));
            }

            return(false);
        }
Esempio n. 6
0
        ////////////////////////////////////////////////////////////////////////
        //
        //  Equals
        //
        //  Implements Object.Equals().  Returns a boolean indicating whether
        //  or not object refers to the same CultureInfo as the current instance.
        //
        ////////////////////////////////////////////////////////////////////////
        public override bool Equals(Object obj)
        {
            TextInfo that = obj as TextInfo;

            if (that != null)
            {
                return(CultureName.Equals(that.CultureName));
            }

            return(false);
        }
        private bool IsCultureNameMatched()
        {
            if (!_configuration.ConstrainTranslatedRoutesByCurrentUICulture)
            {
                return(true);
            }

            // If no translations are available, then obviously the answer is yes.
            if (!_configuration.TranslationProviders.Any())
            {
                return(true);
            }

            var currentUICultureName        = Thread.CurrentThread.CurrentUICulture.Name;
            var currentUINeutralCultureName = currentUICultureName.Split('-').First();

            // If this is a translated route:
            if (DefaultRoute != null)
            {
                // Match if the current UI culture matches the culture name of this route.
                if (currentUICultureName.ValueEquals(CultureName))
                {
                    return(true);
                }

                // Match if the culture name is neutral and no translation exists for the specific culture.
                if (CultureName.Split('-').Length == 1 &&
                    currentUINeutralCultureName == CultureName &&
                    !DefaultRoute.Translations.Any(t => t.CultureName.ValueEquals(currentUICultureName)))
                {
                    return(true);
                }
            }
            else
            {
                // If this is a default route:

                // Match if this route has no translations.
                if (!Translations.Any())
                {
                    return(true);
                }

                // Match if this route has no translations for the neutral current UI culture.
                if (!Translations.Any(t => t.CultureName == currentUINeutralCultureName))
                {
                    return(true);
                }
            }

            // Otherwise, don't match.
            return(false);
        }
Esempio n. 8
0
            public async Task CheckValidityAsync(CallContext callContext)
            {
                await QueryValidationHelper.CheckUserExistsAsync(callContext.DbContext, UserId);

                if (CultureName != CultureName.Trim())
                {
                    throw new InvalidOperationException("Invalid Name: not trimmed");
                }
                if (CultureName.Length < MinNameLength || CultureName.Length > MaxNameLength)
                {
                    throw new InvalidOperationException($"Invalid culture name '{CultureName}'");
                }
            }
Esempio n. 9
0
 private SupportedCultures()
 {
     foreach (string CultureName in Settings.Default.SupportedUICultures.Split(','))
     {
         try
         {
             var CultureInfo = new CultureInfo(CultureName.Trim());
             Add(CultureInfo.Name, CultureInfo.TextInfo.ToTitleCase(CultureInfo.NativeName));
         }
         catch (Exception ex)
         {
             Debug.Print($"An exception occurred while adding the culture {CultureName} to the list of supported cultures. {ex.StackTrace}");
         }
     }
 }
Esempio n. 10
0
        private SupportedCultures()
        {
            CultureInfo CultureInfo = default(CultureInfo);

            foreach (string CultureName in Settings.Default.SupportedUICultures.Split(','))
            {
                try
                {
                    CultureInfo = new CultureInfo(CultureName.Trim());
                    Add(CultureInfo.Name, CultureInfo.TextInfo.ToTitleCase(CultureInfo.NativeName));
                }
                catch (Exception ex)
                {
                    Debug.Print(string.Format("An exception occurred while adding the culture \'{0}\' to the list of supported cultures. {1}", CultureName, ex.ToString()));
                }
            }
        }
Esempio n. 11
0
        //
        // Titlecasing:
        // -----------
        // Titlecasing refers to a casing practice wherein the first letter of a word is an uppercase letter
        // and the rest of the letters are lowercase.  The choice of which words to titlecase in headings
        // and titles is dependent on language and local conventions.  For example, "The Merry Wives of Windor"
        // is the appropriate titlecasing of that play's name in English, with the word "of" not titlecased.
        // In German, however, the title is "Die lustigen Weiber von Windsor," and both "lustigen" and "von"
        // are not titlecased.  In French even fewer words are titlecased: "Les joyeuses commeres de Windsor."
        //
        // Moreover, the determination of what actually constitutes a word is language dependent, and this can
        // influence which letter or letters of a "word" are uppercased when titlecasing strings.  For example
        // "l'arbre" is considered two words in French, whereas "can't" is considered one word in English.
        //
        public unsafe string ToTitleCase(string str)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }
            if (str.Length == 0)
            {
                return(str);
            }

            StringBuilder result        = new StringBuilder();
            string        lowercaseData = null;
            // Store if the current culture is Dutch (special case)
            bool isDutchCulture = CultureName.StartsWith("nl-", StringComparison.OrdinalIgnoreCase);

            for (int i = 0; i < str.Length; i++)
            {
                UnicodeCategory charType;
                int             charLen;

                charType = CharUnicodeInfo.InternalGetUnicodeCategory(str, i, out charLen);
                if (char.CheckLetter(charType))
                {
                    // Special case to check for Dutch specific titlecasing with "IJ" characters
                    // at the beginning of a word
                    if (isDutchCulture && i < str.Length - 1 && (str[i] == 'i' || str[i] == 'I') && (str[i + 1] == 'j' || str[i + 1] == 'J'))
                    {
                        result.Append("IJ");
                        i += 2;
                    }
                    else
                    {
                        // Do the titlecasing for the first character of the word.
                        i = AddTitlecaseLetter(ref result, ref str, i, charLen) + 1;
                    }

                    //
                    // Convert the characters until the end of the this word
                    // to lowercase.
                    //
                    int lowercaseStart = i;

                    //
                    // Use hasLowerCase flag to prevent from lowercasing acronyms (like "URT", "USA", etc)
                    // This is in line with Word 2000 behavior of titlecasing.
                    //
                    bool hasLowerCase = (charType == UnicodeCategory.LowercaseLetter);
                    // Use a loop to find all of the other letters following this letter.
                    while (i < str.Length)
                    {
                        charType = CharUnicodeInfo.InternalGetUnicodeCategory(str, i, out charLen);
                        if (IsLetterCategory(charType))
                        {
                            if (charType == UnicodeCategory.LowercaseLetter)
                            {
                                hasLowerCase = true;
                            }
                            i += charLen;
                        }
                        else if (str[i] == '\'')
                        {
                            i++;
                            if (hasLowerCase)
                            {
                                if (lowercaseData == null)
                                {
                                    lowercaseData = ToLower(str);
                                }
                                result.Append(lowercaseData, lowercaseStart, i - lowercaseStart);
                            }
                            else
                            {
                                result.Append(str, lowercaseStart, i - lowercaseStart);
                            }
                            lowercaseStart = i;
                            hasLowerCase   = true;
                        }
                        else if (!IsWordSeparator(charType))
                        {
                            // This category is considered to be part of the word.
                            // This is any category that is marked as false in wordSeprator array.
                            i += charLen;
                        }
                        else
                        {
                            // A word separator. Break out of the loop.
                            break;
                        }
                    }

                    int count = i - lowercaseStart;

                    if (count > 0)
                    {
                        if (hasLowerCase)
                        {
                            if (lowercaseData == null)
                            {
                                lowercaseData = ToLower(str);
                            }
                            result.Append(lowercaseData, lowercaseStart, count);
                        }
                        else
                        {
                            result.Append(str, lowercaseStart, count);
                        }
                    }

                    if (i < str.Length)
                    {
                        // not a letter, just append it
                        i = AddNonLetter(ref result, ref str, i, charLen);
                    }
                }
                else
                {
                    // not a letter, just append it
                    i = AddNonLetter(ref result, ref str, i, charLen);
                }
            }
            return(result.ToString());
        }
Esempio n. 12
0
 ////////////////////////////////////////////////////////////////////////
 //
 //  GetHashCode
 //
 //  Implements Object.GetHashCode().  Returns the hash code for the
 //  CultureInfo.  The hash code is guaranteed to be the same for CultureInfo A
 //  and B where A.Equals(B) is true.
 //
 ////////////////////////////////////////////////////////////////////////
 public override int GetHashCode()
 {
     return(CultureName.GetHashCode());
 }
Esempio n. 13
0
 public override int GetHashCode()
 {
     return(CultureName.ToUpperInvariant().GetHashCode());
 }
Esempio n. 14
0
 public bool Equals(TranslationInfo ti)
 {
     return((ti != null) ? CultureName.Equals(ti.CultureName, StringComparison.OrdinalIgnoreCase) : false);
 }
Esempio n. 15
0
        public List <Inline> ComposeActivityText(bool includeInTheGame)
        {
            CultureName   current     = CultureHelper.GetCurrent();
            List <Inline> inlinesList = new List <Inline>();

            if (this.GameActivity.type == "install")
            {
                inlinesList.Add((Inline)this.GetRunInstalledTheGame());
            }
            else if (this.GameActivity.type == "level")
            {
                if (current != CultureName.KZ)
                {
                    GameActivityHeader.AddInlines(inlinesList, (Inline)this.GetRunReached(), (Inline)this.GetRunLevelValue(), (Inline)this.GetRunLevel(), (Inline)this.GetRunInTheGame(includeInTheGame));
                }
                else
                {
                    GameActivityHeader.AddInlines(inlinesList, (Inline)this.GetRunInTheGame(includeInTheGame), (Inline)this.GetRunLevelValue(), (Inline)this.GetRunLevel(), (Inline)this.GetRunReached());
                }
            }
            else if (this.GameActivity.type == "activity")
            {
                if (current != CultureName.KZ)
                {
                    GameActivityHeader.AddInlines(inlinesList, (Inline)this.GetRunActivity(), (Inline)this.GetRunInTheGame(includeInTheGame));
                }
                else
                {
                    GameActivityHeader.AddInlines(inlinesList, (Inline)this.GetRunInTheGame(includeInTheGame), (Inline)this.GetRunActivity());
                }
            }
            else if (this.GameActivity.type == "score")
            {
                if (current != CultureName.KZ)
                {
                    GameActivityHeader.AddInlines(inlinesList, (Inline)this.GetRunScored(), (Inline)this.GetRunScoreValue(), (Inline)this.GetRunPoints(), (Inline)this.GetRunInTheGame(includeInTheGame));
                }
                else
                {
                    GameActivityHeader.AddInlines(inlinesList, (Inline)this.GetRunInTheGame(includeInTheGame), (Inline)this.GetRunScoreValue(), (Inline)this.GetRunPoints(), (Inline)this.GetRunScored());
                }
            }
            else if (this.GameActivity.type == "achievement")
            {
                if (current != CultureName.KZ)
                {
                    GameActivityHeader.AddInlines(inlinesList, (Inline)this.GetRunAchievement(), (Inline)this.GetRunInTheGame(includeInTheGame));
                }
                else
                {
                    GameActivityHeader.AddInlines(inlinesList, (Inline)this.GetRunInTheGame(includeInTheGame), (Inline)this.GetRunAchievement());
                }
            }
            if (includeInTheGame)
            {
                Run runGameTitle = this.GetRunGameTitle();
                if (current == CultureName.KZ)
                {
                    inlinesList.Insert(0, (Inline)runGameTitle);
                }
                else
                {
                    inlinesList.Add((Inline)runGameTitle);
                }
            }
            inlinesList.Insert(0, (Inline)this.GetRunName());
            return(inlinesList);
        }
Esempio n. 16
0
        /// <summary>
        /// Compares this CultureTextViewModel instance with another instance to determine the sort
        /// order in the editor view.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo(CultureTextViewModel other)
        {
            string otherName = other.CultureName;

            if (string.Compare(CultureName, otherName, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                //System.Diagnostics.Debug.WriteLine(CultureName + " = " + otherName + " (1)");
                return(0);                  // Exact match
            }

            if (CultureName.Length >= 2 && otherName.Length >= 2)
            {
                // Prefer primary culture (with or without region; if set)
                if (!string.IsNullOrEmpty(TextKeyVM.MainWindowVM.PrimaryCulture))
                {
                    // tP:  thisPrimary
                    // oP:  otherPrimary
                    // oPR: otherPrimaryRelated
                    //
                    //             !tPR         tPR
                    //             !tP    tP    !tP   tP
                    //           --------------------------
                    // !oPR  !oP | cont.  xxx | -1    -1  |
                    //       oP  |  xxx   xxx | xxx   xxx |
                    //           --------------------------
                    // oPR   !oP |   1    xxx | cont. -1  |
                    //       oP  |   1    xxx |  1    xxx |
                    //           --------------------------

                    bool thisPrimary         = string.Compare(CultureName, TextKeyVM.MainWindowVM.PrimaryCulture, StringComparison.InvariantCultureIgnoreCase) == 0;
                    bool thisPrimaryRelated  = CultureName.StartsWith(TextKeyVM.MainWindowVM.PrimaryCulture.Substring(0, 2));
                    bool otherPrimary        = string.Compare(otherName, TextKeyVM.MainWindowVM.PrimaryCulture, StringComparison.InvariantCultureIgnoreCase) == 0;
                    bool otherPrimaryRelated = otherName.StartsWith(TextKeyVM.MainWindowVM.PrimaryCulture.Substring(0, 2));

                    if (thisPrimary || thisPrimaryRelated && !otherPrimaryRelated)
                    {
                        //System.Diagnostics.Debug.WriteLine(CultureName + " < " + otherName + " (2)");
                        return(-1);
                    }
                    if (otherPrimary || otherPrimaryRelated && !thisPrimaryRelated)
                    {
                        //System.Diagnostics.Debug.WriteLine(CultureName + " > " + otherName + " (2)");
                        return(1);
                    }
                }

                if (string.Compare(CultureName.Substring(0, 2), otherName.Substring(0, 2), StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    // Same language, prefer shorter names (without region)
                    if (CultureName.Length != otherName.Length)
                    {
                        int i = CultureName.Length - otherName.Length;
                        //if (i < 0)
                        //    System.Diagnostics.Debug.WriteLine(CultureName + " < " + otherName + " (3)");
                        //else if (i > 0)
                        //    System.Diagnostics.Debug.WriteLine(CultureName + " > " + otherName + " (3)");
                        //else
                        //    System.Diagnostics.Debug.WriteLine(CultureName + " = " + otherName + " (3)");
                        return(i);
                        // If this.length < other.length, then the result is negative and this comes before other
                    }
                }
            }
            return(string.Compare(CultureName, otherName, StringComparison.InvariantCultureIgnoreCase));
        }
Esempio n. 17
0
 public bool Equals(TranslationInfo ti)
 {
     return(!ReferenceEquals(ti, null) && CultureName.Equals(ti.CultureName, StringComparison.OrdinalIgnoreCase));
 }