2) When i Rename "Resource.ja.resx" to "Resource.ja1.resx" its able to generate Designer File with code , Which i thing is the not propper way to call resource.
Because the "ja" in the "Resource.ja.resx" is
a specific culture specified in the CultureInfo class."ja1" is
not a specific culture specified in the CultureInfo class, so the Designer.cs file
will be created
ASP.NET uses the resource file that best matches the setting of the
CurrentUICulture property. The UI culture of the thread is set
according tothe UI culture of the page.
For example, if the current UI culture is Japanese, it is ASP. NET uses a compiled version of the
Resource.ja.resx file. If there is no match for the current UI culture, ASP.NET uses
resource fallback. It starts by searching for resources
for a specific culture. If those are not available, it searches for the resources for
a neutral culture. If these are not found, ASP.NET loads the default resource file.The default resource file in this example is
Resource.resx.
Resource.ja.resx only needs to add name and value, and then it can be used. I made an example to help you understand the
Resource File.
Model
public class test
{
[Display(Name = "hello", ResourceType = typeof(Resource))]
public string Name{get;set;}
}
public class Languages
{
public string LanguageFullName { get; set; }
public string LanguageCultureName { get; set; }
}
CommonController
public class CommonController : Controller
{
protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
{
string lang = null;
HttpCookie langCookie = Request.Cookies["culture"];
if (langCookie != null)
{
lang = langCookie.Value;
}
else
{
var userLanguage = Request.UserLanguages;
var userLang = userLanguage != null ? userLanguage[0] : "";
if (userLang != "")
{
lang = userLang;
}
else
{
lang = LanguageMang.GetDefaultLanguage();
}
}
new LanguageMang().SetLanguage(lang);
return base.BeginExecuteCore(callback, state);
}
}
LanguageMang
public class LanguageMang
{
public static List<Languages> AvailableLanguages = new List<Languages> {
new Languages {
LanguageFullName = "Defalut", LanguageCultureName = "en"
},
new Languages {
LanguageFullName = "Japanese", LanguageCultureName = "ja"
}
};
public static bool IsLanguageAvailable(string lang)
{
return AvailableLanguages.Where(a => a.LanguageCultureName.Equals(lang)).FirstOrDefault() != null ? true : false;
}
public static string GetDefaultLanguage()
{
return AvailableLanguages[0].LanguageCultureName;
}
public void SetLanguage(string lang)
{
try
{
if (!IsLanguageAvailable(lang)) lang = GetDefaultLanguage();
var cultureInfo = new CultureInfo(lang);
Thread.CurrentThread.CurrentUICulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureInfo.Name);
HttpCookie langCookie = new HttpCookie("culture", lang);
langCookie.Expires = DateTime.Now.AddYears(1);
HttpContext.Current.Response.Cookies.Add(langCookie);
}
catch (Exception) { }
}
}
Test13Controller
public class Test13Controller : CommonController
{
public ActionResult Index()
{
return View();
}
public ActionResult ChangeLanguage(string lang)
{
new LanguageMang().SetLanguage(lang);
return RedirectToAction("Index", "Test13");
}
}
View
@model WebApplication26.Models.test
<ul>
@foreach (var i in WebApplication26.Tool.LanguageMang.AvailableLanguages)
{
<li>@Html.ActionLink(i.LanguageFullName, "ChangeLanguage", "Test13", new { lang = i.LanguageCultureName }, null)</li>
}
</ul>
@Html.DisplayNameFor(m => m.Name)
Here is the result.
Best Regards,
YihuiSun
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
None
0 Points
2 Posts
Designer resx file remains empty after adding New Resource File
Aug 10, 2020 01:54 PM|mishraashok5@gmail.com|LINK
Hi There,
I am working on a Globalization Project,
For English Translation i have added default Resource.resx file.
For other language(Japanese) i have added another resource file as Resource.ja.resx file.
When i generate Designer file for the Japanese resource file(Resource.ja.resx) its remain empty
Below Steps I have follwed to resolved but still i am unable to generate Designer files code.
1) set CustomTools = PublicResXFileCodeGenerator and
Build Action = Embedded Resource in Resource.resx file property (Not working)
2) When i Rename "Resource.ja.resx" to "Resource.ja1.resx" its able to generate Designer File with code , Which i thing is the not propper way to call resource.
Contributor
2760 Points
786 Posts
Re: Designer resx file remains empty after adding New Resource File
Aug 11, 2020 07:36 AM|YihuiSun|LINK
Hi mishraashok5,
Model
public class test { [Display(Name = "hello", ResourceType = typeof(Resource))] public string Name{get;set;} } public class Languages { public string LanguageFullName { get; set; } public string LanguageCultureName { get; set; } }
CommonController
LanguageMang
Test13Controller
View
Here is the result.
Best Regards,
YihuiSun