示例#1
0
        public ResourceRecord GetResourceValue(string page, string culture, string key)
        {
            ResourceRecord resource = null;

            using (var conn = new NpgsqlConnection(ConnectionString))
            {
                using (var cmd = new NpgsqlCommand("dblocalizer_get_by_type_and_culture")
                {
                    CommandType = CommandType.StoredProcedure
                })
                {
                    cmd.Connection = conn;
                    conn.Open();

                    cmd.Parameters.AddWithValue("_resource_page", NpgsqlDbType.Text, page);
                    cmd.Parameters.AddWithValue("_culture_code", NpgsqlDbType.Text, culture);
                    cmd.Parameters.AddWithValue("_resource_key", NpgsqlDbType.Text, key);

                    using (var reader = cmd.ExecuteReader())
                        while (reader.Read())
                            resource = new ResourceRecord(reader);
                }
            }
            return resource;
        }
示例#2
0
        private string GetExportPath(string basePath, ResourceRecord record)
        {
            string fileName = record.Page + (record.CultureCode == "en"
                ? string.Empty
                : "." + record.CultureCode) + ".resx";

            string fullExportPath = Path.Combine(basePath, fileName);
            if (!Directory.Exists(fullExportPath.Substring(0, fullExportPath.LastIndexOf(@"\"))))
                Directory.CreateDirectory(fullExportPath.Substring(0, fullExportPath.LastIndexOf(@"\")));
            return fullExportPath;
        }
示例#3
0
 public void ImportResxFile(string resxPath, string rootPath, string defaultCulture = "en-US", bool globalResource = false)
 {
     using (var resxFile = new ResXResourceReader(resxPath))
     {
         var dictEnumerator = resxFile.GetEnumerator();
         while (dictEnumerator.MoveNext())
         {
             var record = new ResourceRecord(_connectionString)
             {
                 Page = GetPagePath(resxPath, rootPath, globalResource),
                 CultureCode = GetCulture(resxPath, defaultCulture),
                 Key = dictEnumerator.Key.ToString(),
                 Value = dictEnumerator.Value.ToString()
             };
             record.Save();
             Console.WriteLine(string.Format("Saved record for page {0}, key: {1} value: {2}", record.Page, record.Key, record.Value));
         }
     }
 }