コード例 #1
0
        public ActionResult GetResources()
        {
            var lm = new LocalizationManager();
            var rm = ClientMessages.ResourceManager;

            //using the thread culture to get the resx
            var data = lm.GetAll(rm);
            var tm = new JsTranslationsScriptManager
            {
                DefaultLanguageEntries = lm.GetAll(rm, new CultureInfo("en")), //if set, in case any translation is missing will look for it in English.
                VariableName = "MyTranslations" //Translations is the default variable name.
            };

            //generate the script
            var script = tm.GetScript(data);
            return JavaScript(script);

            /* RETURN VALUE   ****************************************************************************************************

               var MyTranslations = {  'Accept': 'Aceptar',  'Action': 'Acción',  'Add': 'Adicional',  'Yes': 'Si',  '_Date': 'Fecha',  'OnlyEnglish': 'OnlyEnglish' };

               - The default variable name is Translations but we have customized it.

               *********************************************************************************************************************/
        }
コード例 #2
0
ファイル: ResourcesTests.cs プロジェクト: codecoding/jsresx
 public void GetResourcesUsesTranslationsAsDefaultVar()
 {
     var tm = new JsTranslationsScriptManager
     {
         DefaultLanguageEntries = _lm.GetAll(_rm, new CultureInfo("en"))
     };
     var script = tm.GetScript(_data);
     const string COMPARE = @"var Translations = {""Accept"":""Aceptar"",""Action"":""Acción"",""Add"":""Adicional"",""Yes"":""Si"",""_Date"":""Fecha"",""OnlyEnglish"":""OnlyEnglish""};";
     Assert.IsTrue(script == COMPARE);
 }
コード例 #3
0
ファイル: ResourcesTests.cs プロジェクト: codecoding/jsresx
        public void GetScriptReturnsEmptyStringIfDictionaryIsNull()
        {
            var tm = new JsTranslationsScriptManager
            {
                DefaultLanguageEntries = _lm.GetAll(_rm, new CultureInfo("en")),
                VariableName = "MyTranslations"
            };

            var script = tm.GetScript(null);
            Assert.IsTrue(script == string.Empty);
        }
コード例 #4
0
ファイル: ResourcesTests.cs プロジェクト: codecoding/jsresx
        public void GetResourcesWithoutDefaultCultureDoesntReturnsDefaultValues()
        {
            var tm = new JsTranslationsScriptManager
            {
                DefaultLanguageEntries = _lm.GetAll(_rm)
            };

            //generate the script
            var script = tm.GetScript(_data);
            const string COMPARE = @"var Translations = {""Accept"":""Aceptar"",""Action"":""Acción"",""Add"":""Adicional"",""Yes"":""Si"",""_Date"":""Fecha""};";
            Assert.IsTrue(script == COMPARE);
        }