Ejemplo n.º 1
0
 public void UpsertTranslation(string appName, string key, string lang, Translation value)
 {
     var dataBase = _serverWrapper.ServerConnection.GetDatabase(appName);
     var collection = dataBase.GetCollection<LocalizedString>(LOCALIZATION_COLLECTION_NAME + "_" + lang);
     collection.EnsureIndex(new IndexKeysBuilder().Ascending("key"), IndexOptions.SetUnique(true));
     var localized = collection.Find(Query.EQ("key", key)).FirstOrDefault();
     if (localized == null)
     {
         List<Translation> trans = new List<Translation>();
         trans.Add(value);
         collection.Insert(new LocalizedString()
         {
             Key = key,
             Translation = value
         });
     }
     else
     {
         localized.Translation = value;
         collection.Save(localized);
     }
 }
Ejemplo n.º 2
0
        private void button5_Click(object sender, EventArgs e)
        {
            //WebRequest req = HttpWebRequest.Create("http://dataservice.datingbook.com/get_local");
            //req.Method = "POST";
            //req.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
            //using (var dataStream = req.GetRequestStream())
            //{
            //    var bytes = Encoding.UTF8.GetBytes("lang=IL");
            //    dataStream.Write(bytes, 0, bytes.Length);
            //}

            //HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            //StreamReader reader = new StreamReader(res.GetResponseStream(), Encoding.UTF8);

            string localizedStr = File.ReadAllText(@"E:\dev\Dating\DatingBook\trunk\DatingBook.Web.DataService\static\local\local_en.json");
            //reader.ReadToEnd();
            //reader.Close();
            var localized = Newtonsoft.Json.Linq.JObject.Parse(localizedStr);

            LocalizationDataProvider prov = new LocalizationDataProvider();
            foreach (JProperty local in localized["data"])
            {
                //local.Value
                Translation trans = new Translation()
                {
                    Options = new List<TransKeyVal>(),
                    Value = local.Name
                };
                foreach (JObject val in local)
                {
                    foreach (var prop in val.Properties())
                    {
                        if (prop.Name == "label")
                        {
                            trans.Value = prop.Value.ToString();
                        }
                        else
                        {
                            trans.Options.Add(new TransKeyVal()
                            {
                                Key = prop.Name,
                                Value = prop.Value.ToString()
                            });
                        }
                    }
                }

                prov.UpsertTranslation("gokapara-newyork", local.Name, "english", trans);
            }
        }
Ejemplo n.º 3
0
        private void InsertLocalization(string appName, string lang)
        {
            var filePath = HttpContext.Current.Server.MapPath(string.Format("~/static/local/local_{0}.json", lang));
            string localization = File.ReadAllText(filePath, Encoding.UTF8);
            var localized = JObject.Parse(localization);

            foreach (JProperty local in localized["data"])
            {
                Translation trans = new Translation()
                {
                    Options = new List<TransKeyVal>(),
                    Value = local.Name
                };
                foreach (JObject val in local)
                {
                    foreach (var prop in val.Properties())
                    {
                        if (prop.Name == "label")
                        {
                            trans.Value = prop.Value.ToString();
                        }
                        else
                        {
                            trans.Options.Add(new TransKeyVal()
                            {
                                Key = prop.Name,
                                Value = prop.Value.ToString()
                            });
                        }
                    }
                }

                _localizationDataProvider.UpsertTranslation(appName, local.Name, lang, trans);
            }
        }