Esempio n. 1
0
        public TextLocal GenerateTextLocal(TextCode textCode, Language lang, List <string> listParams)
        {
            TextLocal textLocal;

            if (textCode == null)
            {
                return(null);
            }

            // a textLocal exists for this languageCode?
            TextLocalModel textLocalModel = _reposit.Finder.FindTextLocal(lang.LanguageCode, textCode.Id);

            if (textLocalModel != null)
            {
                textLocal = GenerateTextLocal(textCode, textLocalModel, listParams);
                return(textLocal);
            }

            // no textLocal found, get the mainLanguageCode of the languageCode
            MainLanguageCode mainLanguageCode = lang.MainLanguageCode;

            // convert the mainLanguageCode to a languageCode
            LanguageCode languageCode = LanguageDef.ToLanguageCode(mainLanguageCode);

            // load the textLocal
            textLocalModel = _reposit.Finder.FindTextLocal(languageCode, textCode.Id);

            textLocal = GenerateTextLocal(textCode, textLocalModel, listParams);
            return(textLocal);
        }
Esempio n. 2
0
        protected TextLocal GenerateTextLocal(TextCode textCode, TextLocalModel textLocalModel, List <string> listParams)
        {
            TextLocal textLocal = new TextLocal();

            textLocal.TextLocalModelId = textLocalModel.Id;

            // insert params
            if (listParams != null)
            {
                // check the params count
                // todo:
                try
                {
                    textLocal.Text = string.Format(textLocalModel.Text, listParams.ToArray());
                }
                catch
                {
                    // error!
                    textLocal.Text = textLocalModel.Text;
                }
            }
            else
            {
                textLocal.Text = textLocalModel.Text;
            }

            return(textLocal);
        }
Esempio n. 3
0
        public void ChangeCurrentLang_GetTextLocal_ok()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

            //----Define languages in the current catalog
            core.Editor.DefineLanguage(LanguageCode.en);    // ->becomes the default language
            core.Editor.DefineLanguage(LanguageCode.fr);

            // create textCode and translation
            TextCode       tcName     = core.Editor.CreateTextCode("Name");
            TextLocalModel tl_en_Name = core.Editor.CreateTextLocalModel(LanguageCode.en, tcName, "Name");
            TextLocalModel tl_fr_Name = core.Editor.CreateTextLocalModel(LanguageCode.fr, tcName, "Nom");

            // create textCode and translation
            TextCode tcNameToshiba = core.Editor.CreateTextCode("NameToshiba");

            core.Editor.CreateTextLocalModel(LanguageCode.en, tcNameToshiba, "Laptop Toshiba Core i7 RAM 8Go HD 1To Win10");
            core.Editor.CreateTextLocalModel(LanguageCode.fr, tcNameToshiba, "Ordinateur portable Toshiba Core i7 RAM 8Go DD 1To Win10");

            // change the current language from en to fr
            core.Searcher.SetCurrentLanguage(LanguageCode.fr);

            // get localized text
            TextLocal tlNameFound = core.Editor.GenerateTextLocal(tcName);

            // should be in french
            Assert.AreEqual(tl_fr_Name.Id, tlNameFound.TextLocalModelId, "the TextLocal Language should be 'en'");
        }
Esempio n. 4
0
        public void CreateTextLocal_NoLanguageDefined_Failed()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

            TextCode tcName = core.Editor.CreateTextCode("Name");

            TextLocalModel tlmName = core.Editor.CreateTextLocalModel(LanguageCode.en, tcName, "Name");

            Assert.IsNull(tlmName, "should be null, lang is not defined");
        }
Esempio n. 5
0
        //public bool SaveTextLocalMain(TextLocalMain textLocalMain)
        //{
        //    textLocalMain.Id = Guid.NewGuid().ToString();

        //    _sysData.ListTextLocalMain.Add(textLocalMain);
        //    return true;
        //}


        public bool SaveTextLocal(TextLocalModel textLocal)
        {
            // check that the code is not already used
            // TODO:

            textLocal.Id = Guid.NewGuid().ToString();

            _sysData.ListTextLocal.Add(textLocal);
            return(true);
        }
Esempio n. 6
0
        public void CreateTextLocal_Failed()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

            //----set defined (activate) language codes in the current catalog
            core.Editor.DefineLanguage(LanguageCode.en);

            TextCode tcName = core.Editor.CreateTextCode("Name");

            TextLocalModel tlmName = core.Editor.CreateTextLocalModel(LanguageCode.en_GB, tcName, "Name");

            Assert.IsNull(tlmName, "Can't be created");
        }
Esempio n. 7
0
        //public bool SaveTextLocalMain(TextLocalMain textLocalMain)
        //{
        //    try
        //    {
        //        textLocalMain.Id = ObjectId.NewObjectId().ToString();
        //        _sysData.DBEngine.Insert<TextLocalMain>(textLocalMain);
        //        return true;
        //    }
        //    catch
        //    {
        //        throw new Exception("Error, Can't save the TextLocalMain.");
        //        //return false;
        //    }
        //}

        public bool SaveTextLocal(TextLocalModel textLocal)
        {
            try
            {
                textLocal.Id = ObjectId.NewObjectId().ToString();
                _sysData.DBEngine.Insert <TextLocalModel>(textLocal);
                return(true);
            }
            catch
            {
                throw new Exception("Error, Can't save the TextLocal.");
                //return false;
            }
        }
Esempio n. 8
0
        public void CreateTextLocal_Ok()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

            //----set defined (activate) language codes in the current catalog
            core.Editor.DefineLanguage(LanguageCode.en);

            TextCode tcName = core.Editor.CreateTextCode("Name");

            // create localized text for main languages managed in the application
            // en -> en_uk, en_us,....
            TextLocalModel tlmName = core.Editor.CreateTextLocalModel(LanguageCode.en, tcName, "Name");

            Assert.IsNotNull(tlmName.Id, "id should be set");
            Assert.AreEqual(tcName.Id, tlmName.TextCodeId, "textCode id should match");
            Assert.AreEqual("Name", tlmName.Text, "text should be set");
        }
        public void CreateTextWithOneParam_ParamNotProvided()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

            //----Define languages in the current catalog
            core.Editor.DefineLanguage(LanguageCode.en);    // ->becomes the default language
            core.Editor.DefineLanguage(LanguageCode.fr);

            // create textCode and translation
            TextCode tcName = core.Editor.CreateTextCode("NameIs", 1);

            TextLocalModel tl_en_Name = core.Editor.CreateTextLocalModel(LanguageCode.en, tcName, "My name is {0}: ");
            TextLocalModel tl_fr_Name = core.Editor.CreateTextLocalModel(LanguageCode.fr, tcName, "Mon nom est {0}: ");

            // get localized text
            List <string> listParams = new List <string>();
            //listParams.Add("Yvan");
            TextLocal tlNameFound = core.Editor.GenerateTextLocal(tcName, listParams);

            // should be in english
            Assert.AreEqual("My name is {0}: ", tlNameFound.Text, "the TextLocal should include the parameter");
        }
Esempio n. 10
0
        public void GetTextLocal_enGB_Get_en()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

            //----Define languages in the current catalog
            core.Editor.DefineLanguage(LanguageCode.en);    // ->becomes the default language
            core.Editor.DefineLanguage(LanguageCode.en_GB);

            // create textCode and translation, only for the en lang
            TextCode       tcName     = core.Editor.CreateTextCode("Name");
            TextLocalModel tl_en_Name = core.Editor.CreateTextLocalModel(LanguageCode.en, tcName, "Name");

            // change the current language from en to en_GB (exp: because the users are in UK)
            core.Searcher.SetCurrentLanguage(LanguageCode.en_GB);


            // get localized text
            TextLocal tlNameFound = core.Editor.GenerateTextLocal(tcName);

            // en textLocal doesn't exists, so return the en main languageCode textLocal
            Assert.AreEqual(tl_en_Name.Id, tlNameFound.TextLocalModelId, "the TextLocal Language should be 'en'");
        }
Esempio n. 11
0
        /// <summary>
        /// Create a localized text for a final language.
        /// exp: en_GB, en_US, fr_FR,...
        /// </summary>
        /// <param name="languageCode"></param>
        /// <param name="tc"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public TextLocalModel CreateTextLocalModel(LanguageCode languageCode, TextCode tc, string text)
        {
            // the language must exists
            Language lang = _reposit.Finder.FindLanguageByCode(languageCode);

            if (lang == null)
            {
                // not defined
                return(null);
            }

            // check the textCode
            // TODO:

            // check the text
            if (text == null)
            {
                return(null);
            }

            // check that not already exists: same languageCode and textCode
            if (_reposit.Finder.FindTextLocal(languageCode, tc.Id) != null)
            {
                return(null);
            }

            // create the localize text
            TextLocalModel textLocal = new TextLocalModel();

            textLocal.TextCodeId   = tc.Id;
            textLocal.LanguageCode = languageCode;
            textLocal.Text         = text;

            // save it
            _reposit.Builder.SaveTextLocal(textLocal);
            return(textLocal);
        }