Exemplo n.º 1
0
        public static void LoadTranslationFile(string cultureCode)
        {
            if (cultureCode == "en")
            {
                return;
            }

            FileInfo translationFile = TranslationFile.GetTranslationFilePath(cultureCode);

            if (File.Exists(translationFile.FullName) == false)
            {
                if (Directory.Exists(translationFile.DirectoryName) == false)
                {
                    Directory.CreateDirectory(translationFile.DirectoryName);
                }
                File.Create(translationFile.FullName).Dispose();
            }

            var translationFileData = NccFileHelper.ReadAllText(translationFile.FullName);

            if (string.IsNullOrWhiteSpace(translationFileData))
            {
                var assembly = typeof(SharedResource).GetTypeInfo().Assembly;
                using (Stream resource = assembly.GetManifestResourceStream("NetCoreCMS.Framework.Resources.SharedResource.lang"))
                {
                    var sr = new StreamReader(resource);
                    translationFileData = sr.ReadToEndAsync().Result;
                    NccFileHelper.WriteAllText(translationFile.FullName, translationFileData);
                }
            }

            _translationFile[cultureCode] = JsonConvert.DeserializeObject <TranslationFileData>(translationFileData);
        }
Exemplo n.º 2
0
        public void SaveTranslations()
        {
            OrderTranslations();
            //var fileData = JsonConvert.SerializeObject(_translationFile[_cultureCode], Formatting.Indented);

            lock (_lockObject)
            {
                //using (var resFile = File.Create(_resourceFilePath))
                //{
                //    var data = Encoding.UTF8.GetBytes(fileData);
                //    resFile.Write(data, 0, data.Length);
                //    resFile.Flush();
                //}

                foreach (var item in SupportedCultures.Cultures)
                {
                    if (item.TwoLetterISOLanguageName == "en")
                    {
                        continue;
                    }

                    var file = TranslationFile.GetTranslationFilePath(item.TwoLetterISOLanguageName);
                    NccFileHelper.WriteObject(file.FullName, _translationFile[item.TwoLetterISOLanguageName]);
                }
            }
        }
Exemplo n.º 3
0
        public static List <TranslationFile> GetTranslationFiles()
        {
            var translationFileList = new List <TranslationFile>();
            var languageFolder      = Path.Combine(GlobalContext.GetResourceFolder(), "Language");

            if (Directory.Exists(languageFolder))
            {
                var files = Directory.GetFiles(languageFolder, "*.lang");
                foreach (var item in files)
                {
                    var fi = new FileInfo(item);
                    var tf = new TranslationFile();
                    tf.Content  = NccFileHelper.ReadAllText(item);
                    tf.FileName = fi.Name;
                    tf.FullPath = item;
                    tf.Group    = "Website";
                    tf.Culture  = GetCultureFromFileName(fi.Name);
                    tf.Id       = Cryptography.GetHash(item);
                    translationFileList.Add(tf);
                }
            }

            return(translationFileList);
        }