Now I am making a news release system which is a small system(about 5 news pre-year) to release some news of an enterprise.
In my opinion, I will use a Controller and a template View to achieve this. The news will only release by editing the source code but not create a brand new heavy release system.
I create a model like this by storing the context of the news and title of the news:
public NewsModel{
public string Title{get;set;}
public string Context{get;set;}
}
Now the problem is there are multi-language of the news, how can I get the localizer to render the Title&Context to the right language in the controller.
how can I get the localizer to render the Title&Context to the right language in the controller.
Follow the official document,you could render the Title&Context(the filed name) by different culture.Where did you make error?I suggest that you could share your simple demo.Or you mean to translate the whole view like using google auto translation?
Best Regards,
Rena
.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.
Now the website can be displayed in Chinese and English. Meanwhile, I can only achieve the Globalization in the view but I don't know how to do it in the model of the News.
And For My point of you, you must be enter multi language name in you database. link if your column name "Firstname" than add one "Firstnamefrench". and enter both lextbox with a proper name.
while bind, check if browser language fr than call "Firstnamefrench" else "Firstname".
You need to modify the resource file name like below:
And you need to add the respective String1 and String2 to Views.Home.News.en.resx and Views.Home.News.zh-hans.resx like below(do not delete the data in your View.Home.en.resx,just modify the name):
.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.
Member
53 Points
246 Posts
How can I get the localizer in the controller?
Sep 09, 2019 03:19 AM|mywatermelon|LINK
Now I am making a news release system which is a small system(about 5 news pre-year) to release some news of an enterprise.
In my opinion, I will use a Controller and a template View to achieve this. The news will only release by editing the source code but not create a brand new heavy release system.
I create a model like this by storing the context of the news and title of the news:
public NewsModel{
public string Title{get;set;}
public string Context{get;set;}
}
Now the problem is there are multi-language of the news, how can I get the localizer to render the Title&Context to the right language in the controller.
I followed the tutorial of Microsoft to achieve Globalization by using the resoureces:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-3.0 but I don't know how to solve this.
Contributor
2710 Points
874 Posts
Re: How can I get the localizer in the controller?
Sep 09, 2019 09:05 AM|Rena Ni|LINK
Hi mywatermelon,
Follow the official document,you could render the Title&Context(the filed name) by different culture.Where did you make error?I suggest that you could share your simple demo.Or you mean to translate the whole view like using google auto translation?
Best Regards,
Rena
Member
53 Points
246 Posts
Re: How can I get the localizer in the controller?
Sep 10, 2019 02:18 AM|mywatermelon|LINK
Hello, here is the demo:
https://1drv.ms/u/s!AtcqjirAlaGYir9Pdj2CFIxKpbSCVA?e=2xZZFs
Now the website can be displayed in Chinese and English. Meanwhile, I can only achieve the Globalization in the view but I don't know how to do it in the model of the News.
How can I solve this? Thank you.
Participant
1968 Points
1026 Posts
MVP
Re: How can I get the localizer in the controller?
Sep 10, 2019 06:05 AM|maherjendoubi|LINK
Hi,
https://stackoverflow.com/questions/48528878/how-to-get-localized-string-from-asp-net-core-controller-using-istringlocalizer
Best regards,
Maher
Blog : https://maherjendoubi.io
Participant
850 Points
492 Posts
Re: How can I get the localizer in the controller?
Sep 10, 2019 06:21 AM|AddWeb Solution|LINK
Hi mywatermelon,
Its very Big option so plz refers below link for understanding :
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-2.2
And For My point of you, you must be enter multi language name in you database. link if your column name "Firstname" than add one "Firstnamefrench". and enter both lextbox with a proper name.
while bind, check if browser language fr than call "Firstnamefrench" else "Firstname".
Member
53 Points
246 Posts
Re: How can I get the localizer in the controller?
Sep 10, 2019 07:40 AM|mywatermelon|LINK
I won't use a database for it is just a small amount of data yet.
And also, thus I modified the code of the demo project(https://1drv.ms/u/s!AtcqjirAlaGYir9Pdj2CFIxKpbSCVA?e=2xZZFs) as the tutorial you showed, it still can not display the language correctly.
Contributor
2710 Points
874 Posts
Re: How can I get the localizer in the controller?
Sep 10, 2019 08:45 AM|Rena Ni|LINK
Hi mywatermelon,
You need to modify the resource file name like below:
And you need to add the respective String1 and String2 to Views.Home.News.en.resx and Views.Home.News.zh-hans.resx like below(do not delete the data in your View.Home.en.resx,just modify the name):
My project:https://microsoftapc-my.sharepoint.com/:u:/g/personal/v-renni_microsoft_com/EayLigXtOoVMmxakffC6_8MBYSKeEdPkvGBWaVWeER7qGw?e=uWA7yq
Best Regards,
Rena
Member
53 Points
246 Posts
Re: How can I get the localizer in the controller?
Sep 10, 2019 08:52 AM|mywatermelon|LINK
Well, it works. That's interesting. Thank you.