Ejemplo n.º 1
0
    static string[] getRowData(LocaleIdentifier locId)
    {
        var locStr = locId.ToString();
        var loc    = new Locale(locId);
        var values = new string[count];

        Func <string, string> normalize = (string str) => {
            // wrong i
            if (locStr == "be-Cyrl-BY")
            {
                str = str.Replace('i', 'і');
            }
            // convert \u00FF part of CLDR string to char
            return(decodeUnicodeLiteral(str));
        };

        // **** CALENDAR
        XPathNavigator gregorian;

        gregorian = loc.FindOrDefault("//calendar[@type=\"gregorian\"]//monthContext[@type=\"stand-alone\"]/monthWidth[@type=\"wide\"]");
        if (gregorian != null)
        {
            gregorian.Select("./*/text()").Cast <object>().Select(o => normalize(o.ToString())).ToArray(values, monthsIdx);
        }

        gregorian = loc.FindOrDefault("//calendar[@type=\"gregorian\"]//monthContext[@type=\"format\"]/monthWidth[@type=\"wide\"]");
        if (gregorian != null)
        {
            gregorian.Select("./*/text()").Cast <object>().Select(o => normalize(o.ToString())).ToArray(values, smonthsIdx);
        }

        gregorian = loc.FindOrDefault("//calendar[@type=\"gregorian\"]//dayContext[@type=\"stand-alone\"]/dayWidth[@type=\"wide\"]");
        if (gregorian != null && loc.ToString() != "lrc-Arab-IQ" && loc.ToString() != "lrc-Arab-IR" && loc.ToString() != "mzn-Arab-IR")
        {
            gregorian.Select("./*/text()").Cast <object>().Select(o => normalize(o.ToString())).ToArray(values, daysIdx);
        }

        gregorian = loc.FindOrDefault("//calendar[@type=\"gregorian\"]//dayContext[@type=\"format\"]/dayWidth[@type=\"wide\"]");
        if (gregorian != null && loc.ToString() != "lrc-Arab-IQ" && loc.ToString() != "lrc-Arab-IR" && loc.ToString() != "mzn-Arab-IR")
        {
            gregorian.Select("./*/text()").Cast <object>().Select(o => normalize(o.ToString())).ToArray(values, sdaysIdx);
        }


        // **** SPELL NUMBERS
        try {
            var spell = SpellingFormatter.Create(loc, new SpellingOptions {
                Style = SpellingStyle.Cardinal
            });
            numsSource.Select(n => normalize(spell.Format(n))).ToArray(values, numsIdx);
        } catch { }
        try {
            var spell = SpellingFormatter.Create(loc, new SpellingOptions {
                Style = SpellingStyle.Ordinal
            });
            numsSource.Select(n => normalize(spell.Format(n))).ToArray(values, snumsIdx);
        } catch { }

        return(values);
    }
        public static LocaleIdentifier LocaleLabelToId(string label)
        {
            LocaleIdentifier id = default;

            Debug.Assert(TryGetLocaleLabelToId(label, out id), $"Expected label {label} to be a Locale label.");
            return(id);
        }
Ejemplo n.º 3
0
    public static IEnumerable <LangMatrixRow> fromNetCultureInfos(LocaleIdentifier[] cldrSpecifics)
    {
        // get NON cldr culture data
        var cldrs = new HashSet <string>(cldrSpecifics.Select(c => c.Language));

        return(CultureInfo.GetCultures(CultureTypes.AllCultures).
               Select(cu => {
            LocaleIdentifier lid = null;
            { try { lid = LocaleIdentifier.Parse(cu.Name); } catch { } }
            if (
                lid == null ||
                string.IsNullOrEmpty(lid.Region) ||
                char.IsDigit(lid.Region[0]) ||
                cldrs.Contains(lid.Language)
                )
            {
                return null;
            }

            var res = CldrUtils.getNetRowData(cu, lid.Language, lid.Region, out LocaleIdentifier locId);
            return new LangMatrixRow {
                lang = locId.ToString(),
                row = res,
            };
        }).
               Where(lt => lt != null));
    }
Ejemplo n.º 4
0
    public static void Parse(Dictionary <string, LangMatrixRow> res)
    {
        var googleLocsCodes = File.ReadAllLines(Directory.GetCurrentDirectory() + @"\google\googleTrans.txt").
                              Select(l => l.Split('\t')).
                              Select(p => p[1].Split(' ')[0].Replace("**", "")).
                              ToArray();
        var googleLocs = googleLocsCodes.
                         Select(w => LocaleIdentifier.Parse(w).MostLikelySubtags()).
                         ToArray();
        var oks = googleLocs.
                  Select(loc => Langs.fullNameToMeta.TryGetValue(loc.ToString(), out Langs.CldrLang cl) ? cl : null).
                  NotNulls().
                  ToArray();
        var wrongs = googleLocs.
                     Select(loc => Langs.fullNameToMeta.TryGetValue(loc.ToString(), out Langs.CldrLang cl) ? null : loc.ToString()).
                     NotNulls().
                     ToArray();

        if (googleLocsCodes.Length != oks.Length)
        {
            throw new Exception();
        }
        oks.ForEach((item, idx) => {
            var row    = LangsDesignLib.adjustNewfulltextDataRow(res, item.Id.ToString());
            row.row[7] = googleLocsCodes[idx];
        });
    }
Ejemplo n.º 5
0
    public static void Build()
    {
        var langs      = Corpus.DownloadWikies.getUrls().Where(u => u.size > /*1000000*/ 0).Select(u => u.name.Split(new string[] { "wi" }, StringSplitOptions.RemoveEmptyEntries)[0]).Distinct().ToArray();
        var lmLangs    = Langs.meta.Select(l => l.Lang).Distinct().ToArray();
        var notInWiki  = lmLangs.Except(langs).ToArray();
        var validLangs = langs.Where(l => LocaleIdentifier.TryParse(l, out LocaleIdentifier li)).ToArray();
        var wikiLocs   = validLangs.Select(l => LocaleIdentifier.Parse(l).MostLikelySubtags().ToString()).ToArray();
        var oks        = wikiLocs.
                         Select(loc => Langs.fullNameToMeta.TryGetValue(loc.ToString(), out Langs.CldrLang cl) ? cl : null).
                         NotNulls().
                         ToArray();
        var wrongs = wikiLocs.
                     Select(loc => Langs.fullNameToMeta.TryGetValue(loc.ToString(), out Langs.CldrLang cl) ? null : loc).
                     NotNulls().
                     ToArray();
        //ALPHAs
        // from clibs\utils\unicode\unicodeBlocks.json
        //Armi (http://zuga.net/articles/unicode/script/imperial-aramaic/) and Goth (? https://en.wikipedia.org/wiki/Gothic_alphabet) missing
        var alphas = new HashSet <String> {
            "Latn", "Zyyy", "Grek", "Copt", "Cyrl", "Armn", "Hebr", "Arab", "Syrc", "Thaa", "Nkoo", "Samr", "Mand", "Deva", "Beng", "Guru", "Gujr", "Orya", "Taml", "Telu", "Knda", "Mlym", "Sinh", "Thai", "Laoo", "Tibt", "Mymr", "Geor", "Hang", "Ethi", "Cher", "Cans", "Ogam", "Runr", "Tglg", "Hano", "Buhd", "Tagb", "Khmr", "Mong", "Limb", "Tale", "Talu", "Bugi", "Lana", "Bali", "Sund", "Batk", "Lepc", "Olck", "Glag", "Tfng", "Hira", "Kana", "Bopo", "Hani", "Yiii", "Lisu", "Vaii", "Bamu", "Sylo", "Phag", "Saur", "Kali", "Rjng", "Java", "Cham", "Tavt", "Mtei"
        };
        var wrongAlphas = wrongs.Where(l => !alphas.Contains(LocaleIdentifier.Parse(l).Script)).ToArray();

        //var path = LangsDesignDirs.cldrRepo;
    }
Ejemplo n.º 6
0
        public void FromDefault_EqualsDefault()
        {
            LocaleIdentifier li1 = default;
            LocaleIdentifier li2 = default;

            Assert.AreEqual(li1, li2);
        }
Ejemplo n.º 7
0
    public static void exportForWikibulary()
    {
        var metaData     = XElement.Load(@"D:\rewise\design\langsDesign\cldr\supplementalData.xml");
        var fromMetadata = metaData.Descendants("languagePopulation").Select(e => e.Attribute("type").Value.Replace('_', '-')).ToArray();
        var fromMain     = Directory.GetFiles(@"d:\wikibulary\data\cldr\common\main", "*.xml", SearchOption.TopDirectoryOnly)
                           .Select(fn => Path.GetFileNameWithoutExtension(fn).Replace('_', '-'))
                           .ToArray();
        var missing = File.ReadAllLines(@"d:\rewise\design\langsDesign\cldr\langs-for-export.txt");
        //.Select(l => {
        //  if (!LocaleIdentifier.TryParse(l, out var li)) return null;
        //  return new { lang = l, likely = li.MostLikelySubtags().ToString() };
        //});
        var fromMeta = Langs.meta.Select(m => m.Id);
        //var fromMeta = Langs.meta.Select(m => new { lang = m.Id, likely = LocaleIdentifier.Parse(m.Id).MostLikelySubtags().ToString() });
        var fromCulture = CultureInfo.GetCultures(CultureTypes.AllCultures)//.Where(c => !wrong.Contains(c.Name))
                          .Select(c => c.Name).ToArray();
        //.Select(c => {
        //  if (!LocaleIdentifier.TryParse(c.Name, out var li)) return null;
        //  return new { lang = c.Name, likely = li.MostLikelySubtags().ToString() };
        //});

        var wrong = new HashSet <string> {
            "no", "", "root"
        };
        var all = fromMetadata.Concat(fromMain).Concat(fromMeta).Concat(fromCulture).Concat(missing)
                  .Where(l => l != null && !wrong.Contains(l)).Distinct().ToArray();

        var res = all
                  .Select(l => new {
            lang   = l,
            likely = LocaleIdentifier.TryParse(l, out var li) ? li.MostLikelySubtags().ToString() : null
        })
Ejemplo n.º 8
0
        public void SystemLanguageMapsToLocaleIdentifier(SystemLanguage lang)
        {
            var localeId = new LocaleIdentifier(lang);

            Assert.IsNotNull(localeId.CultureInfo, "Expected the SystemLanguage to be mapped to a cultureInfo but it was not." + localeId);
            Assert.IsNotEmpty(localeId.Code, "Expected the locale to extract a valid code from the SystemLanguage but it did not." + localeId);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates an empty XLIFF document ready for populating.
        /// </summary>
        /// <param name="source">The source language. The language used when populating <see cref="ITranslationUnit.Source"/>.</param>
        /// <param name="target">The target language. The language used when populating <see cref="ITranslationUnit.Target"/>.</param>
        /// <param name="version">The XLIFF file version.</param>
        /// <returns></returns>
        public static IXliffDocument CreateDocument(LocaleIdentifier source, LocaleIdentifier target, XliffVersion version)
        {
            var doc = XliffDocument.Create(version);

            doc.SourceLanguage = source.Code;
            doc.TargetLanguage = target.Code;
            return(doc);
        }
        void Start()
        {
            // Create a locale to represent Japanese.
            var localeId = new LocaleIdentifier(SystemLanguage.Japanese);
            var locale   = Locale.CreateLocale(localeId);

            // Customize the name.
            locale.name = "Japanese(日本)";
        }
Ejemplo n.º 11
0
        static void ImportFileNode(IFile file, LocaleIdentifier source, LocaleIdentifier target, ImportOptions importOptions)
        {
            // Find the string table and collection for this file
            var collection = FindProjectCollection(file);

            // Import translation units which have no groups.
            INoteCollection extraNodes = file;

            if (file.TranslationUnitCount > 0)
            {
                if (collection == null)
                {
                    var dir = importOptions.NewCollectionDirectory;
                    if (string.IsNullOrEmpty(dir))
                    {
                        dir = EditorUtility.SaveFolderPanel($"Create new String Table Collection {file.Id}", "Assets", file.Id);
                    }

                    if (!string.IsNullOrEmpty(dir))
                    {
                        var newCollection = LocalizationEditorSettings.CreateStringTableCollection(file.Id, dir);
                        extraNodes = null;
                        ImportFileIntoCollection(newCollection, file, source, target, importOptions);
                    }
                }
                else
                {
                    extraNodes = null;
                    ImportFileIntoCollection(collection, file, source, target, importOptions);
                }
            }

            for (int i = 0; i < file.GroupCount; ++i)
            {
                var group           = file.GetGroup(i);
                var groupCollection = FindProjectCollection(group) ?? collection;
                if (groupCollection == null)
                {
                    // Use the provided directory otherwise ask the user to provide one
                    var dir = importOptions.NewCollectionDirectory;
                    if (string.IsNullOrEmpty(dir))
                    {
                        dir = EditorUtility.SaveFolderPanel($"Create new String Table Collection {file.Id}", "Assets", file.Id);
                        if (string.IsNullOrEmpty(dir))
                        {
                            continue;
                        }
                    }
                    var collectionName = string.IsNullOrEmpty(group.Name) ? group.Id : group.Name;
                    groupCollection = LocalizationEditorSettings.CreateStringTableCollection(collectionName, dir);
                }

                ImportGroupIntoCollection(groupCollection, group, extraNodes, source, target, importOptions);
            }
        }
 /// <summary>
 /// Attempt to retrieve a Locale using the identifier.
 /// </summary>
 /// <param name="id"><see cref="LocaleIdentifier"/> to find.</param>
 /// <returns>If no Locale can be found then null is returned.</returns>
 public Locale GetLocale(LocaleIdentifier id)
 {
     foreach (var locale in Locales)
     {
         if (locale.Identifier.Equals(id))
         {
             return(locale);
         }
     }
     return(null);
 }
        void Start()
        {
            // Create a locale identifier to represent English
            var localeEnglishSystemLanguage = new LocaleIdentifier(SystemLanguage.English);
            var localeEnglishCode           = new LocaleIdentifier("en");
            var localeEnglishCi             = new LocaleIdentifier(CultureInfo.GetCultureInfo("en"));

            Debug.Log(localeEnglishSystemLanguage);
            Debug.Log(localeEnglishCode);
            Debug.Log(localeEnglishCi);
        }
Ejemplo n.º 14
0
    public void checkTexts(Dictionary <string, Dictionary <string, string> > protocol)
    {
        var locId  = LocaleIdentifier.Parse(lang);
        var wrongs = UnicodeBlocks.checkBlockNames(row, locId.Script);

        if (wrongs == null)
        {
            return;
        }
        protocol[lang] = wrongs;
    }
        public static bool TryGetLocaleLabelToId(string label, out LocaleIdentifier localeId)
        {
            if (!IsLocaleLabel(label))
            {
                localeId = default;
                return(false);
            }

            localeId = label.Substring(k_AssetLabelPrefix.Length, label.Length - k_AssetLabelPrefix.Length);
            return(true);
        }
        void Start()
        {
            // Create a locale to represent English.
            var localeId = new LocaleIdentifier(SystemLanguage.English);
            var locale   = Locale.CreateLocale(localeId);

            Debug.Log("English locale: " + locale);

            // Create a regional locale to represent English UK.
            var regionalLocaleId = new LocaleIdentifier("en-GB");
            var regionalLocale   = Locale.CreateLocale(regionalLocaleId);

            Debug.Log("English(en-GB) locale: " + regionalLocale);
        }
Ejemplo n.º 17
0
    static string[] getNetRowData(CultureInfo lc, string Language, string Region, out LocaleIdentifier locId)
    {
        var values = new string[count];
        var fmt    = lc.DateTimeFormat;

        fmt.MonthNames.Take(12).ToArray(values, monthsIdx);
        fmt.MonthGenitiveNames.Take(12).ToArray(values, smonthsIdx);
        fmt.DayNames.Take(7).ToArray(values, daysIdx);

        var script = UnicodeBlocks.getBlockNames(values).Select(kv => kv.Key).Single();

        locId = LocaleIdentifier.Parse(string.Format("{0}-{1}-{2}", Language, script, Region));
        return(values);
    }
        void Start()
        {
            // Create a locale to represent English.
            var localeId = new LocaleIdentifier(SystemLanguage.English);
            var locale   = Locale.CreateLocale(localeId);

            // Create a regional locale to represent English UK.
            var regionalLocaleId = new LocaleIdentifier("en-GB");
            var regionalLocale   = Locale.CreateLocale(regionalLocaleId);

            // Fallback from English(UK) to the non-regional English version.
            regionalLocale.FallbackLocale = locale;

            Debug.Log("English(en-GB) will fallback to " + regionalLocale.FallbackLocale);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Exports all <see cref="StringTable"/> in <paramref name="collections"/> as 1 or more XLIFF files where each file represents a single language.
        /// </summary>
        /// <param name="source">This is the language that will be used as the source language for all generated XLIFF files.</param>
        /// <param name="directory">The directory to output the generated XLIFF files.</param>
        /// <param name="name">The default name for all generated XLIFF files. Files will be saved with the full name "[name]_[Language Code].xlf"</param>
        /// <param name="version">The XLIFF version to generate the files in.</param>
        /// <param name="collections">1 or more <see cref="StringTableCollection"/>. The collections will be combines into language groups where each file represents a single </param>
        /// <param name="reporter">Optional reporter which can report the current progress.</param>
        public static void Export(LocaleIdentifier source, string directory, string name, XliffVersion version, ICollection <StringTableCollection> collections, ITaskReporter reporter = null)
        {
            if (collections == null)
            {
                throw new ArgumentNullException(nameof(collections));
            }

            var dict = new Dictionary <StringTableCollection, HashSet <int> >();

            foreach (var c in collections)
            {
                dict[c] = new HashSet <int>(Enumerable.Range(0, c.StringTables.Count));
            }

            ExportSelected(source, directory, name, version, dict, reporter);
        }
Ejemplo n.º 20
0
    public static Langs.CldrLang[] getMissingLangs()
    {
        var wrongs   = new string[] { "ceb", "ht", "hmn", "la", "ny", "sm", "su", Langs.invariantId.Split('-')[0] };
        var wrongsEx = wrongs.Select(w => LocaleIdentifier.Parse(w).MostLikelySubtags()).ToArray();
        var newLangs = wrongsEx.
                       Select(l => new Langs.CldrLang {
            Id            = string.Format("{0}-{1}", l.Language, l.Region),
            Lang          = l.Language,
            ScriptId      = l.Script,
            DefaultRegion = l.Region,
            Regions       = new string[] { l.Region }
        }).
                       ToArray();

        //var newLangsStr = Json.SerializeStr(newLangs);
        return(newLangs);
    }
Ejemplo n.º 21
0
        void UpdateCultureLabels()
        {
            var localeIdentifier = new LocaleIdentifier(m_Code.stringValue);
            var cultureInfo      = localeIdentifier.CultureInfo;

            m_CultureInfoLabel = GenerateCultureLabel(cultureInfo);

            var formatter = Locale.GetFormatter(m_UseCustomFormatter.boolValue, localeIdentifier, m_FormatCultureCode.stringValue);

            m_FormatCultureInfoLabel = GenerateCultureLabel(formatter);

            if (formatter != null)
            {
                m_FormattingExampleDateTime = new GUIContent(DateTime.Now.ToString(formatter));
                m_FormattingExampleCurrency = new GUIContent(string.Format(formatter, "{0:C}", 123));
                m_FormattingExampleNumber   = new GUIContent(string.Format(formatter, "{0:N}", 123456789.12));
            }
        }
Ejemplo n.º 22
0
        static void ImportGroupIntoCollection(StringTableCollection collection, IGroup group, INoteCollection extraNotes, LocaleIdentifier source, LocaleIdentifier target, ImportOptions importOptions)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            var sourceTable = collection.GetTable(source) ?? collection.AddNewTable(source);
            var targetTable = collection.GetTable(target) ?? collection.AddNewTable(target);

            // Extract file comments?
            var generalNotes = AddMetadataCommentsFromNotes(group, collection.SharedData.Metadata, NoteType.General, importOptions.ImportNotes);
            var sourceNotes  = AddMetadataCommentsFromNotes(group, sourceTable, NoteType.Source, importOptions.ImportNotes);
            int targetNotes  = sourceTable != targetTable?AddMetadataCommentsFromNotes(group, targetTable, NoteType.Target, importOptions.ImportNotes) : 0;

            // If we are importing a group and the file contains notes that were not used then we can include them as extras here.
            if (extraNotes != null)
            {
                // If we imported some notes from the group then we need to switch to merge or we will lose those notes.
                var overrideBehavior = generalNotes > 0 ? ImportNotesBehavior.Merge : importOptions.ImportNotes;
                AddMetadataCommentsFromNotes(extraNotes, collection.SharedData.Metadata, NoteType.General, overrideBehavior);

                overrideBehavior = sourceNotes > 0 ? ImportNotesBehavior.Merge : importOptions.ImportNotes;
                AddMetadataCommentsFromNotes(extraNotes, sourceTable, NoteType.Source, overrideBehavior);

                overrideBehavior = targetNotes > 0 ? ImportNotesBehavior.Merge : importOptions.ImportNotes;
                if (sourceTable != targetTable)
                {
                    AddMetadataCommentsFromNotes(extraNotes, targetTable, NoteType.Target, overrideBehavior);
                }
            }

            ImportIntoTables(group, sourceTable as StringTable, targetTable as StringTable, importOptions);
            LocalizationEditorSettings.EditorEvents.RaiseCollectionModified(null, collection);
        }
Ejemplo n.º 23
0
 static string FormatAssetTableCollectionName(LocaleIdentifier localeIdentifier) => string.Format(LocalizationEditorSettings.AssetGroupName, localeIdentifier.Code);
Ejemplo n.º 24
0
        internal static void ExportSelected(LocaleIdentifier source, string dir, string name, XliffVersion version, Dictionary <StringTableCollection, HashSet <int> > collectionsWithSelectedIndexes, ITaskReporter reporter = null)
        {
            var documents = DictionaryPool <LocaleIdentifier, IXliffDocument> .Get();

            try
            {
                // Used for reporting
                int   totalTasks = collectionsWithSelectedIndexes.Sum(c => c.Value.Count);
                float taskStep   = 1.0f / (totalTasks * 2.0f);
                float progress   = 0;
                reporter?.Start($"Exporting {totalTasks} String Tables to XLIFF", string.Empty);

                foreach (var kvp in collectionsWithSelectedIndexes)
                {
                    var stringTableCollection = kvp.Key;
                    var sourceTable           = stringTableCollection.GetTable(source) as StringTable;
                    if (sourceTable == null)
                    {
                        var message = $"Collection {stringTableCollection.TableCollectionName} does not contain a table for the source language {source}";
                        reporter?.Fail(message);
                        throw new Exception(message);
                    }

                    foreach (var stringTableIndex in kvp.Value)
                    {
                        var stringTable = stringTableCollection.StringTables[stringTableIndex];

                        reporter?.ReportProgress($"Generating document for {stringTable.name}", progress);
                        progress += taskStep;

                        if (!documents.TryGetValue(stringTable.LocaleIdentifier, out var targetDoc))
                        {
                            targetDoc = CreateDocument(source, stringTable.LocaleIdentifier, version);
                            documents[stringTable.LocaleIdentifier] = targetDoc;
                        }

                        AddTableToDocument(targetDoc, sourceTable, stringTable);
                    }
                }

                // Now write the files
                foreach (var doc in documents)
                {
                    var cleanName = CleanFileName(name);
                    var fileName  = $"{cleanName}_{doc.Key.Code}.xlf";
                    var filePath  = Path.Combine(dir, fileName);

                    reporter?.ReportProgress($"Writing {fileName}", progress);
                    progress += taskStep;
                    using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
                    {
                        doc.Value.Serialize(stream);
                    }
                }

                reporter?.Completed($"Finished exporting");
            }
            catch (Exception e)
            {
                reporter?.Fail(e.Message);
                throw;
            }
            finally
            {
                DictionaryPool <LocaleIdentifier, IXliffDocument> .Release(documents);
            }
        }
Ejemplo n.º 25
0
        public void SystemLanguageUnknownMapsToUndefined()
        {
            var localeId = new LocaleIdentifier(SystemLanguage.Unknown);

            Assert.AreEqual(LocaleIdentifier.Undefined, localeId);
        }
Ejemplo n.º 26
0
 public Locale GetLocale(LocaleIdentifier id) => Locales.Find(l => l.Identifier == id);
Ejemplo n.º 27
0
        public void GetCultureInfoReturnsNullWhenCodeIsNull()
        {
            LocaleIdentifier id = new LocaleIdentifier((string)null);

            Assert.IsNull(id.CultureInfo);
        }
Ejemplo n.º 28
0
    public static void Build()
    {
        var cldr  = Json.Deserialize <Langs.CldrLang[]>(LangsDirs.dirCldrTexts);
        var roots = cldr.SelectMany(c => c.Regions.Select(r => LocaleIdentifier.Parse(string.Format("{0}-{1}-{2}", c.Lang, c.ScriptId, r)))).ToArray();
        var locs  = roots.Select(root => new Locale(root)).ToArray();

        // ALPHABETS
        var rx     = new Regex("[{} ]");
        var alphas = locs.Select(loc => {
            var localePattern = loc.Find("//characters");
            var data          = localePattern.SelectChildren(XPathNodeType.Element).OfType <XPathNavigator>().Where(al => al.Name == "exemplarCharacters").Select(al => {
                var value   = CldrUtils.decodeUnicodeLiteral(al.Value.Normalize().Trim('[', ']'));
                value       = rx.Replace(value, "");
                var keyNode = al.SelectSingleNode("./@type");
                var key     = keyNode == null ? "root" : keyNode.Value;
                //if (key == "numbers" || key == "punctuation" || string.IsNullOrEmpty(value)) return null;
                return(new { key, value });
            }).Where(n => n != null).ToArray();
            return(new {
                lang = loc.Id.ToString(),
                data
            });
        }).Where(d => d.data.Length > 0).OrderBy(l => l.lang).ToArray();

        Func <string, IEnumerable <LangMatrixRow> > alphasRes = (string key) => alphas.SelectMany(a => a.data.Where(aa => aa.key == key).Select(aa =>
                                                                                                                                                new LangMatrixRow {
            lang = a.lang, columnNames = Linq.Items(aa.key).ToArray(), row = Linq.Items(aa.value).ToArray()
        }));
        var alphaRoot        = new LangMatrix(alphasRes("root"), null, true);
        var alphaAuxlity     = new LangMatrix(alphasRes("auxiliary"), null, true);
        var alphaIndex       = new LangMatrix(alphasRes("index"), null, true);
        var alphaNumbers     = new LangMatrix(alphasRes("numbers"), null, true);
        var alphaPunctuation = new LangMatrix(alphasRes("punctuation"), null, true);

        var patterns = new LangMatrix(locs.Select(loc => {
            var localePattern   = loc.FindOrDefault("//localeDisplayNames/localeDisplayPattern/localePattern").ToString();
            var localeSeparator = loc.FindOrDefault("//localeDisplayNames/localeDisplayPattern/localeSeparator").ToString();
            return(new LangMatrixRow {
                lang = loc.Id.ToString(),
                row = new string[] { localePattern, localeSeparator },
                columnNames = new string[] { "pattern", "separator" },
            });
        }), null, true);
        Dictionary <string, Dictionary <string, string> > langsProtocol = new Dictionary <string, Dictionary <string, string> >();
        var langs = new LangMatrix(
            locs.Select(loc => fromCldr(loc, "//localeDisplayNames/languages")),
            langsProtocol, true
            );
        Dictionary <string, Dictionary <string, string> > scriptsProtocol = new Dictionary <string, Dictionary <string, string> >();
        var scripts = new LangMatrix(
            locs.Select(loc => fromCldr(loc, "//localeDisplayNames/scripts")),
            scriptsProtocol, true
            );
        Dictionary <string, Dictionary <string, string> > regionsProtocol = new Dictionary <string, Dictionary <string, string> >();
        var regions = new LangMatrix(
            locs.Select(loc => fromCldr(loc, "//localeDisplayNames/territories")),
            regionsProtocol, true
            );

        langs.save(LangsDesignDirs.cldr + "cldrNameLangs.csv", true);
        scripts.save(LangsDesignDirs.cldr + "cldrNameScripts.csv", true);
        regions.save(LangsDesignDirs.cldr + "cldrNameRegions.csv", true);
        patterns.save(LangsDesignDirs.cldr + "cldrNamePatterns.csv", true);
        alphaRoot.save(LangsDesignDirs.cldr + "alphaRoot.csv", true);
        alphaAuxlity.save(LangsDesignDirs.cldr + "alphaAuxlity.csv", true);
        alphaIndex.save(LangsDesignDirs.cldr + "alphaIndex.csv", true);
        alphaNumbers.save(LangsDesignDirs.cldr + "alphaNumbers.csv", true);
        alphaPunctuation.save(LangsDesignDirs.cldr + "alphaPunctuation.csv", true);

        // save to DART messages
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\cldrNameLangs.msg", Protobuf.ToBytes(matrixToDart(langs)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\cldrNameScripts.msg", Protobuf.ToBytes(matrixToDart(scripts)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\cldrNameRegions.msg", Protobuf.ToBytes(matrixToDart(regions)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\cldrNamePatterns.msg", Protobuf.ToBytes(matrixToDart(patterns)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\alphaRoot.msg", Protobuf.ToBytes(matrixToDart(alphaRoot)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\alphaAuxlity.msg", Protobuf.ToBytes(matrixToDart(alphaAuxlity)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\alphaIndex.msg", Protobuf.ToBytes(matrixToDart(alphaIndex)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\alphaNumbers.msg", Protobuf.ToBytes(matrixToDart(alphaNumbers)));
        File.WriteAllBytes(LangsDesignDirs.data + @"langsDesign\alphaPunctuation.msg", Protobuf.ToBytes(matrixToDart(alphaPunctuation)));

        //  var localePattern = loc.FindOrDefault("//localeDisplayNames/localeDisplayPattern/localePattern").ToString();
        //  var localeSeparator = loc.FindOrDefault("//localeDisplayNames/localeDisplayPattern/localeSeparator").ToString();
        //  fromCldr(loc, "//localeDisplayNames/languages");
        //  fromCldr(loc, "//localeDisplayNames/scripts");
        //  fromCldr(loc, "//localeDisplayNames/territories");
        //});
    }
Ejemplo n.º 29
0
 /// <summary>
 /// TODO: DOC
 /// </summary>
 /// <param name="localeIdentifier"></param>
 /// <returns></returns>
 public static string FormatAssetLabel(LocaleIdentifier localeIdentifier) => k_AssetLabelPrefix + localeIdentifier.Code;
Ejemplo n.º 30
0
 /// <summary>
 /// TODO: DOC
 /// </summary>
 /// <param name="tableType"></param>
 /// <param name="tableName"></param>
 /// <param name="localeId"></param>
 /// <returns></returns>
 public static string GetTableAddress(string tableName, LocaleIdentifier localeId)
 {
     return($"{tableName}{Seperator}{localeId.Code}");
 }