Пример #1
0
        /// <summary>
        /// First argument is language name
        /// Second argument is number of words (if not specified this is 1)
        /// Thrid argument is number of sylaballes per word (if not specified this is random)
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            var langs = new Languages();

            if (args.Length == 0)
            {
                Console.WriteLine(Properties.Resources.Msg_No_Language);
                return;
            }
            var lang = args[0].ToLowerInvariant();

            if (!langs.ContainsKey(lang))
            {
                Console.WriteLine(string.Format(Properties.Resources.Msg_Language_Not_Found, lang));
                return;
            }
            var wordCount = 1;
            var syl       = -1;

            if (args.Length > 1)
            {
                wordCount = int.Parse(args[1]);

                if (args.Length > 2)
                {
                    syl = int.Parse(args[1]);
                }
            }
            for (var i = 0; i < wordCount; i++)
            {
                Console.WriteLine(langs[lang].GenerateWord(syl));
            }
        }
Пример #2
0
 /// <summary>
 /// Sets the UserLanguage
 /// </summary>
 /// <param name="key">The key of the language</param>
 public static void SetLanguage(string key)
 {
     if (!Languages.ContainsKey(key))
     {
         throw new LoCaException("Couldn't set user language to '" + key + "', because language wasn't found!");
     }
     SetLanguage(Languages[key]);
 }
Пример #3
0
        public async Task InitGuild(IGuild guild)
        {
            if (Languages.ContainsKey(guild.Id)) // If somehow InitGuild is called 2 times for the same guild we ignore it
            {
                return;
            }
            string guildIdStr = guild.Id.ToString();

            if (await R.Db(dbName).Table("Guilds").GetAll(guildIdStr).Count().Eq(0).RunAsync <bool>(conn))
            {
                await R.Db(dbName).Table("Guilds").Insert(R.HashMap("id", guildIdStr)
                                                          .With("Prefix", "s.")
                                                          .With("Language", "en")
                                                          .With("Availability", defaultAvailability)
                                                          ).RunAsync(conn);
            }
            dynamic json = await R.Db(dbName).Table("Guilds").Get(guildIdStr).RunAsync(conn);

            Languages.Add(guild.Id, (string)json.Language);
            Prefixs.Add(guild.Id, (string)json.Prefix);
            string availability = (string)json.Availability;

            if (availability == null)
            {
                Availability.Add(guild.Id, defaultAvailability);
            }
            else
            {
                string newAvailability = availability;
                while (newAvailability.Length < defaultAvailability.Length)
                {
                    newAvailability += "1";
                }
                Availability.Add(guild.Id, newAvailability);
            }
            string anonymize = (string)json.Anonymize;

            if (anonymize != null)
            {
                Anonymize.Add(guild.Id, bool.Parse(anonymize));
            }
            else
            {
                Anonymize.Add(guild.Id, false);
            }
            string anime = (string)json.animeSubscription;

            if (anime != null && anime != "0")
            {
                AnimeSubscription.Add((await guild.GetTextChannelAsync(ulong.Parse(anime)), null));
            }
            string nhentai = (string)json.nhentaiSubscription;

            if (nhentai != null && nhentai != "0")
            {
                NHentaiSubscription.Add((await guild.GetTextChannelAsync(ulong.Parse(nhentai)), Subscription.SubscriptionTags.ParseSubscriptionTags(json.nhentaiSubscriptionTags.ToObject <string[]>(), false)));
            }
        }
Пример #4
0
        /// <summary>
        /// Gets the correct plural key according to the number sent in as count.
        /// </summary>
        /// <returns>The plural key. Will return the passed in key if the language isn't supported</returns>
        /// <param name="languageCode">The ISO-639 language code that's currently loaded</param>
        /// <param name="baseKey">The original key without any plural suffixes</param>
        /// <param name="count">The number of occurrences of the value of the key. e.g. 1 apple, 2 apples</param>
        public static string GetPluralKey(string languageCode, string baseKey, int count)
        {
            if (Languages.ContainsKey(languageCode))
            {
                return(baseKey + "_" + Languages[languageCode](count).ToString());
            }

            return(baseKey);
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultInflector"/> class.
 /// </summary>
 /// <param name="languages">The languages.</param>
 public DefaultInflector(IEnumerable <IInflectorLanguage> languages)
 {
     Languages = languages.Where(x => x.GetType().Assembly != typeof(DefaultInflector).Assembly).ToDictionary(x => x.Name);
     foreach (var Language in languages.Where(x => x.GetType().Assembly == typeof(DefaultInflector).Assembly &&
                                              !Languages.ContainsKey(x.Name)))
     {
         Languages.Add(Language.Name, Language);
     }
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultIndexer"/> class.
 /// </summary>
 /// <param name="indexCreators">The index creators.</param>
 public DefaultIndexer(IEnumerable <IIndexCreator> indexCreators)
 {
     Languages = indexCreators.Where(x => x.GetType().Assembly != typeof(DefaultIndexer).Assembly).ToDictionary(x => x.Name);
     foreach (var Language in indexCreators.Where(x => x.GetType().Assembly == typeof(DefaultIndexer).Assembly &&
                                                  !Languages.ContainsKey(x.Name)))
     {
         Languages.Add(Language.Name, Language);
     }
 }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultStemmer"/> class.
 /// </summary>
 /// <param name="languages">The languages.</param>
 public DefaultStemmer(IEnumerable <IStemmerLanguage> languages)
 {
     Languages = languages.Where(x => x.GetType().Assembly != typeof(DefaultStemmer).Assembly).ToDictionary(x => x.ISOCode);
     foreach (var Language in languages.Where(x => x.GetType().Assembly == typeof(DefaultStemmer).Assembly &&
                                              !Languages.ContainsKey(x.ISOCode)))
     {
         Languages.Add(Language.ISOCode, Language);
     }
 }
Пример #8
0
        /// <summary>
        /// Sets the value of a string in a specified language
        /// </summary>
        /// <param name="id">String id</param>
        /// <param name="message">Message</param>
        /// <param name="language">Language name</param>
        public void SetString(int id, string message, string language)
        {
            if (!Languages.ContainsKey(language))
            {
                return;
            }

            Languages[language].SetString(id, message);
        }
Пример #9
0
        /// <summary>
        ///     Add the specified language to this object
        /// </summary>
        public void AddLanguage(string languageCode, bool copyValues)
        {
            if (Languages.ContainsKey(languageCode.ToLower()))
            {
                return;
            }

            // Create the file
            var cleanFilename = Filename.Substring(0, Filename.LastIndexOf('.'));
            var newFilename   = $"{cleanFilename}.{languageCode}.resx";

            File.Delete(newFilename);

            using (var writer = new ResXResourceWriter(newFilename))
            {
                if (copyValues)
                {
                    using (var reader = new ResXResourceReader(Filename))
                    {
                        reader.UseResXDataNodes = true;
                        var dataEnumerator = reader.GetEnumerator();
                        while (dataEnumerator.MoveNext())
                        {
                            var key  = (string)dataEnumerator.Key;
                            var node = (ResXDataNode)dataEnumerator.Value;
                            if (!IsLocalizableString(key, node))
                            {
                                continue;
                            }

                            var value = node.GetValueAsString();
                            // Skip saving unnecessary items
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                writer.AddResource(key, value);
                            }
                        }
                    }
                }
                writer.Generate();
            }

            // Add the created file to this ResourceHolder
            var languageHolder = new LanguageHolder(languageCode, newFilename);

            Languages.Add(languageCode.ToLower(), languageHolder);

            _stringsTable.Columns.Add(languageCode.ToLower());

            ReadResourceFile(languageHolder.Filename, _stringsTable, languageHolder.LanguageId, true);

            EvaluateAllRows();

            Dirty = true;
            OnLanguageChange();
        }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultTokenizer"/> class.
 /// </summary>
 /// <param name="languages">The languages.</param>
 /// <param name="objectPool">The object pool.</param>
 public DefaultTokenizer(IEnumerable <ITokenizerLanguage> languages, ObjectPool <StringBuilder> objectPool)
 {
     Languages = languages.Where(x => x.GetType().Assembly != typeof(DefaultTokenizer).Assembly).ToDictionary(x => x.ISOCode);
     foreach (var Language in languages.Where(x => x.GetType().Assembly == typeof(DefaultTokenizer).Assembly &&
                                              !Languages.ContainsKey(x.ISOCode)))
     {
         Languages.Add(Language.ISOCode, Language);
     }
     ObjectPool = objectPool;
 }
Пример #11
0
        /// <summary>
        /// Gets a Language
        /// </summary>
        /// <param name="name">Name</param>
        /// <returns></returns>
        public Language GetLanguage(string name)
        {
            if (!Languages.ContainsKey(name))
            {
                return(null);
            }


            return(Languages[name]);
        }
Пример #12
0
 public void AddLanguage(string language)
 {
     if (Languages.ContainsKey(language))
     {
         Languages[language]++;
     }
     else
     {
         Languages.Add(language, 1);
     }
 }
Пример #13
0
        public static Dictionary <string, string> GetLocalisationDic(string lang)
        {
            CultureInfo culture = new CultureInfo(lang);

            if (Languages.ContainsKey(culture))
            {
                return(Languages[culture]);
            }
            else
            {
                return(new Dictionary <string, string>());
            }
        }
Пример #14
0
        /// <summary>
        /// Remove a language
        /// </summary>
        /// <param name="name"></param>
        public void RemoveLanguage(string name)
        {
            if (Languages.ContainsKey(name))
            {
                Languages.Remove(name);
            }

            if (CurrentLanguage.Name == name)
            {
                CurrentLanguage = null;
                Default         = string.Empty;
            }
        }
Пример #15
0
        //
        // Public Methods
        //
        #region Public Methods

        /// <summary>
        /// This is how to access the data.
        /// </summary>
        /// <param name="language"></param>
        /// <returns></returns>
        public ResXUnifiedIndexer this[string language]
        {
            get
            {
                lock (lck)
                {
                    if (Languages.ContainsKey(language))
                    {
                        return(new ResXUnifiedIndexer(this, language));
                    }
                    return(new ResXUnifiedIndexer());
                }
            }
        }
Пример #16
0
        /// <summary>
        /// Returns all strings
        /// </summary>
        /// <param name="languagename">Name of the language</param>
        /// <returns></returns>
        public List <string> GetStrings(string languagename)
        {
            List <string> list = new List <string>();

            if (!Languages.ContainsKey(languagename))
            {
                return(list);
            }

            Language lang = Languages[languagename];


            return(list);
        }
Пример #17
0
        /// <summary>
        ///     Delete a language from this object (including its file)
        /// </summary>
        public void DeleteLanguage(string languageCode)
        {
            if (!Languages.ContainsKey(languageCode.ToLower()))
            {
                return;
            }

            File.Delete(Languages[languageCode.ToLower()].Filename);

            Languages.Remove(languageCode.ToLower());
            _stringsTable.Columns.RemoveAt(_stringsTable.Columns[languageCode].Ordinal);

            OnLanguageChange();
        }
Пример #18
0
        public static CultureInfo GetLanguage(int index)
        {
            if (Languages.ContainsKey(index))
            {
                switch (Languages[index])
                {
                case "Français":
                    return(new CultureInfo("fr-FR"));

                case "English":
                    return(new CultureInfo("en-US"));
                }
            }
            return(new CultureInfo("en-US"));
        }
Пример #19
0
            /// <summary>
            /// Sets the language to the device language (en-US) or the language prefix (en) or to nothing if not found
            /// </summary>
            public static void SetUserLanguage()
            {
                LocaleListCompat lst = ConfigurationCompat.GetLocales(Resources.System.Configuration);

                if (Languages.ContainsKey(lst.ToLanguageTags()))
                {
                    SetLanguage(Languages[lst.ToLanguageTags()]);
                    Log.Debug("LoCa", "Set language to " + lst.ToLanguageTags());
                    return;
                }
                if (Languages.ContainsKey(lst.ToLanguageTags().Split('-')[0]))
                {
                    SetLanguage(Languages[lst.ToLanguageTags().Split('-')[0]]);
                    Log.Debug("LoCa", "Set language to " + lst.ToLanguageTags().Split('-')[0]);
                    return;
                }
            }
Пример #20
0
        /// <summary>
        /// Get translation
        /// </summary>
        /// <param name="key">Key</param>
        /// <returns>Value</returns>
        public string GetTranslation(string key)
        {
            string ret = null;

            if (key != null)
            {
                if (Languages.ContainsKey(Culture))
                {
                    LanguageData language = Languages[Culture];
                    if (language != null)
                    {
                        if (language.Translations.ContainsKey(key))
                        {
                            ret = language.Translations[key];
                        }
                    }
                }
                if (ret == null)
                {
                    if (Languages.ContainsKey(FallbackCulture))
                    {
                        LanguageData language = Languages[FallbackCulture];
                        if (language != null)
                        {
                            if (language.Translations.ContainsKey(key))
                            {
                                ret = language.Translations[key];
                            }
                        }
                    }
                }
                if (ret == null)
                {
                    ret = "{$" + key + "$}";
                }
            }
            else
            {
                ret = "{$NULL$}";
            }
            return(ret);
        }
Пример #21
0
        public static void SelectLanguage()
        {
            string currLang = System.Globalization.CultureInfo.CurrentCulture.Name;

            foreach (KeyValuePair <string, Language> kvp in Languages)
            {
                var lang = kvp.Value;
                if (Configuration.Language == "" && lang.Key.Substring(2) == currLang.Substring(2))
                {
                    CurrentLanguage = lang;
                }
                if (Configuration.Language != "" && lang.Key == Configuration.Language)
                {
                    CurrentLanguage = lang;
                }
            }
            if (CurrentLanguage == null && Languages.ContainsKey("en-US"))
            {
                CurrentLanguage = Languages["en-US"];
            }
        }
Пример #22
0
        public bool HasMissingTranslations(string cultureName)
        {
            var rows = _stringsTable.Rows.Cast <DataRow>().ToList();

            if (Settings.Default.TranslatableInBrackets)
            {
                rows.RemoveAll(dataRow =>
                {
                    var defaultValue = ((string)dataRow[Properties.Resources.ColNameNoLang]).Trim();
                    return(!defaultValue.StartsWith("[", StringComparison.InvariantCultureIgnoreCase) ||
                           !defaultValue.EndsWith("]", StringComparison.InvariantCultureIgnoreCase));
                });
            }

            if (!rows.Any())
            {
                return(false);
            }

            return(!Languages.ContainsKey(cultureName) || rows.Any(row => !RowContainsTranslation(row, cultureName)));
        }
Пример #23
0
        /// <summary>
        /// Returns a string in a specified language
        /// </summary>
        /// <param name="id">String id</param>
        /// <param name="language">Language name</param>
        /// <returns>Formated string</returns>
        public string GetString(int id, string language)
        {
            if (!Languages.ContainsKey(language))
            {
                return(string.Empty);
            }


            string str = string.Empty;

            try
            {
                str = Languages[language].GetString(id);
            }
            catch (KeyNotFoundException)
            {
                // Oops, not found at all !!
                return(string.Empty);
            }

            return(str);
        }
Пример #24
0
        public async Task InitGuild(ulong guildId)
        {
            if (Languages.ContainsKey(guildId)) // If somehow InitGuild is called 2 times for the same guild we ignore it
            {
                return;
            }
            string guildIdStr = guildId.ToString();

            if (await R.Db(dbName).Table("Guilds").GetAll(guildIdStr).Count().Eq(0).RunAsync <bool>(conn))
            {
                await R.Db(dbName).Table("Guilds").Insert(R.HashMap("id", guildIdStr)
                                                          .With("Prefix", "s.")
                                                          .With("Language", "en")
                                                          .With("Availability", defaultAvailability)
                                                          ).RunAsync(conn);
            }
            dynamic json = await R.Db(dbName).Table("Guilds").Get(guildIdStr).RunAsync(conn);

            Languages.Add(guildId, (string)json.Language);
            Prefixs.Add(guildId, (string)json.Prefix);
            string availability = (string)json.Availability;

            if (availability == null)
            {
                Availability.Add(guildId, defaultAvailability);
            }
            else
            {
                string newAvailability = availability;
                while (newAvailability.Length < defaultAvailability.Length)
                {
                    newAvailability += "1";
                }
                Availability.Add(guildId, newAvailability);
            }
        }
Пример #25
0
        public static bool IsSupportedCulture(CultureInfo ci)
        {
            string neutral = ci.IsNeutralCulture ? ci.Name : ci.Parent.Name;

            return(Languages.ContainsKey(neutral));
        }
Пример #26
0
        public async Task TranslateDeck(string guid, string language, bool createCards)
        {
            await ApiClient.Login();

            if (!Languages.ContainsKey(language))
            {
                throw new Exception("Language not supported");
            }
            CurrentLanguage = Languages[language];

            var deck = await ApiClient.GetByGuid <Deck>(guid);

            if (deck == null)
            {
                throw new Exception("Deck not found");
            }

            var newDeck = new Deck()
            {
                Name = $"{deck.Name} ({language})"
            };

            newDeck = await ApiClient.Create(newDeck);

            var counter = 1;
            var total   = deck.DeckCards.Count;

            foreach (var deckCard in deck.DeckCards.OrderBy(x => x.Card.Name))
            {
                var card = await ApiClient.GetByGuid <Card>(deckCard.Card.Guid);

                Card newCard;
                if (createCards)
                {
                    Console.WriteLine($"Creating card {counter++}/{total} : {card.Name} ({language} wip)");
                    newCard = await CreateCard(card, language);

                    await Task.Delay(30 * 1000);
                }
                else
                {
                    var cardSearchOptions = new CardSearchOptions
                    {
                        Search     = $"{card.Name} ({language}",
                        PageNumber = 1,
                        PageSize   = 10
                    };
                    var result = await ApiClient.Search <Card, CardSearchOptions>(cardSearchOptions);

                    newCard = result.Items?.FirstOrDefault();
                    await Task.Delay(1000);
                }

                if (newCard != null)
                {
                    var newDeckCard = new DeckCard()
                    {
                        Card     = newCard,
                        Deck     = newDeck,
                        Quantity = deckCard.Quantity
                    };
                    await ApiClient.Create(newDeckCard);

                    await Task.Delay(1000);
                }
            }
        }
Пример #27
0
        private void SaveInternal(TranslationCollection translations, Dictionary <int, string> DisplayFolderLanguages, Dictionary <int, string> DescriptionLanguages, SSAS.TabularTranslationObjectAnnotation annotation)
        {
            List <int> listAllLanguages = new List <int>(Languages.Keys);

            foreach (int iLang in DisplayFolderLanguages.Keys)
            {
                if (!listAllLanguages.Contains(iLang))
                {
                    listAllLanguages.Add(iLang);
                }
            }
            foreach (int iLang in DescriptionLanguages.Keys)
            {
                if (!listAllLanguages.Contains(iLang))
                {
                    listAllLanguages.Add(iLang);
                }
            }

            List <SSAS.TabularTranslationAnnotation> listAnnotations = new List <TabularTranslationAnnotation>();

            translations.Clear();
            foreach (int iLang in listAllLanguages)
            {
                Translation t = new Translation(iLang);
                if (translations is AttributeTranslationCollection)
                {
                    t = new AttributeTranslation(iLang);
                }
                if (DisplayFolderLanguages.ContainsKey(iLang))
                {
                    t.DisplayFolder = DisplayFolderLanguages[iLang];
                }
                if (DescriptionLanguages.ContainsKey(iLang))
                {
                    t.Description = DescriptionLanguages[iLang];
                }

                if (Languages.ContainsKey(iLang) && !string.IsNullOrEmpty(Languages[iLang]))
                {
                    t.Caption = Languages[iLang];
                }
                else if (!string.IsNullOrEmpty(t.DisplayFolder) || !string.IsNullOrEmpty(t.Description))
                {
                    t.Caption = this.DefaultLanguage; //this works around a problem where if they translate the display folder or the description but not the caption, then the caption ends up blank
                }
                if (!string.IsNullOrEmpty(t.Caption) || !string.IsNullOrEmpty(t.Description) || !string.IsNullOrEmpty(t.DisplayFolder))
                {
                    translations.Add(t);
                    SSAS.TabularTranslationAnnotation tranAnnotation = new TabularTranslationAnnotation();
                    tranAnnotation.Caption       = t.Caption;
                    tranAnnotation.Description   = t.Description;
                    tranAnnotation.DisplayFolder = t.DisplayFolder;
                    tranAnnotation.Language      = t.Language;
                    listAnnotations.Add(tranAnnotation);
                }
            }

            if (annotation != null)
            {
                annotation.TabularTranslations = listAnnotations.ToArray();
            }
        }
 public static bool IsLanguageAvailable(string language) => Languages.ContainsKey(language);