Esempio n. 1
0
        public void GetCultureInfoTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.Equal(6, cultures.GetSupportedCultures().Length);

            Assert.Equal("en", cultures.GetCultureInfo("en").Name);
            Assert.Equal("en-GB", cultures.GetCultureInfo("en-GB").Name);
            Assert.Equal("de-CH", cultures.GetCultureInfo("de-CH").Name);

            Assert.Null(cultures.GetCultureInfo("xxx"));
        }
Esempio n. 2
0
        public string GetText(string resourceName, string uiCultureTab = null, params Object[] list)
        {
            var rc = "[not found]";

            try
            {
                if (_supportedCultures != null)
                {
                    if (_rm == null)
                    {
                        var asm      = typeof(C19QCalcLib.C19QCalcLib).Assembly;
                        var baseName = asm.GetName().Name + ".Properties.Resources";
                        _rm = new ResourceManager(baseName, asm);
                    }

                    var cookies = new MxCookies(_httpContextAccessor);
                    if (_supportedCultures.IsSupported(uiCultureTab) == false)
                    {
                        uiCultureTab = _supportedCultures.GetUiCultureTab(cookies.GetValue(MxSupportedCultures.CookieName));
                    }
                    var uiCultureInfo = _supportedCultures.GetCultureInfo(uiCultureTab);
                    if (uiCultureInfo != null)
                    {
                        var res = _rm?.GetString(resourceName ?? "NotFound", uiCultureInfo) ?? "[Not Found]";
                        rc = string.Format(uiCultureInfo, res, list);
                    }
                }
            }
            catch (Exception e)
            {
                // ReSharper disable once UnusedVariable
                var msg = e.Message;
                //ignore
            }
            return(rc);
        }