Exemplo n.º 1
0
        public ActionResult ExportLanguagePack(string cultureCode)
        {
            int tenantId = WorkContext.CurrentTenant.Id;

            var localizedStrings = localizableStringService.Value.Find(x =>
                                                                       x.TenantId == tenantId &&
                                                                       x.CultureCode == cultureCode &&
                                                                       x.TextValue != null);

            var languagePack = new LanguagePackFile
            {
                CultureCode      = cultureCode,
                LocalizedStrings = localizedStrings.ToDictionary(k => k.TextKey, v => v.TextValue)
            };

            string json     = languagePack.ToJson();
            string fileName = string.Format("{0}_LanguagePack_{1}_{2:yyyy-MM-dd}.json", siteSettings.SiteName, cultureCode, DateTime.Now);

            return(File(new UTF8Encoding().GetBytes(json), "application/json", fileName));
        }
    //PackFileをロードします
    public bool LoadFile(LanguagePackFile file, bool dontDestroyOnLoad)
    {
        LanguagePack pack = new LanguagePack(dontDestroyOnLoad);

        string        labelKey = null;
        List <string> textList = null;
        string        text     = null;

        try
        {
            string filePath = Application.dataPath + "/" + file.packFileName;

            //Debug.Log(filePath);
            //FileInfo fileInfo = new FileInfo(filePath);
            //StreamReader streamReader = new StreamReader(fileInfo.Open(FileMode.Open, FileAccess.Read), Encoding.UTF8);

            using (StreamReader reader = new StreamReader(@filePath, Encoding.UTF8))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.StartsWith(LabelToken))
                    {
                        if (text != null)
                        {
                            textList.Add(text);
                        }

                        if (textList != null)
                        {
                            pack.AddLable(labelKey, textList);
                        }

                        labelKey = line.Substring(LabelToken.Length).Trim();
                        textList = new List <string>();
                        text     = null;
                        continue;
                    }

                    if (line.StartsWith(ListToken))
                    {
                        if (text != null)
                        {
                            textList.Add(text);
                        }

                        text = DecodeLine(line.Substring(ListToken.Length));

                        continue;
                    }

                    text += DecodeLine(line);
                }

                if (text != null)
                {
                    textList.Add(text);
                }

                if (textList != null)
                {
                    pack.AddLable(labelKey, textList);
                }


                reader.Close();
            }

            languagePackList.Add(pack);

            return(true);
        }
        catch (System.Exception e)
        {
            Debug.LogWarning("LanguagePackManager.LoadFiles >> Failed: " + e.Message);

            return(false);
        }
    }