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.

               *********************************************************************************************************************/
        }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }