I'm writing a sample project that supports multilanguage. I'm using Resource files for that. I want to use Local Resources.
Here is what I've done.
1. Add 'App_LocalResources' folder in View/Login/ directory.
2. Add 'Logins.resx' for the default language and 'Logins.en.resx' for english language.
3. I've made the Access Modifier as 'Public' and Custom Tool from properties to 'PublicResXFileCodeGenerator' and gave identical Custom Tool Namespace to both of that files ('ViewResource'). After I have changed "Build Action" property is "Embedded Resource"
4. I put 'Username' string into both my resource files and accessed it from my 'Logins.cshtml' view in Views/Login directory like this
@ViewResource.Username
But I can found "ViewResource" namespace for coding. What i do wrong step or miss step?
First check that the resource works in a controller's cs file, if not fix it.
After in cshtml you need to use the full namspace @Namespace.ViewResource.Username. You can add namespaces to the web.config to eliminate this requirement (if you add new namespace in the web.config restart vs, because the razor editor tends to ignore reparsing
the web.config, so you won't get correct intellisense)
meoghe
Member
29 Points
74 Posts
Local Resources for multi language in MVC3
Dec 17, 2012 05:12 AM|LINK
Hello everyone,
I'm writing a sample project that supports multilanguage. I'm using Resource files for that. I want to use Local Resources.
Here is what I've done.
1. Add 'App_LocalResources' folder in View/Login/ directory.
2. Add 'Logins.resx' for the default language and 'Logins.en.resx' for english language.
3. I've made the Access Modifier as 'Public' and Custom Tool from properties to 'PublicResXFileCodeGenerator' and gave identical Custom Tool Namespace to both of that files ('ViewResource'). After I have changed "Build Action" property is "Embedded Resource"
4. I put 'Username' string into both my resource files and accessed it from my 'Logins.cshtml' view in Views/Login directory like this
But I can found "ViewResource" namespace for coding. What i do wrong step or miss step?
stmarti
Contributor
5083 Points
1061 Posts
Re: Local Resources for multi language in MVC3
Dec 17, 2012 08:14 AM|LINK
First check that the resource works in a controller's cs file, if not fix it.
After in cshtml you need to use the full namspace @Namespace.ViewResource.Username. You can add namespaces to the web.config to eliminate this requirement (if you add new namespace in the web.config restart vs, because the razor editor tends to ignore reparsing the web.config, so you won't get correct intellisense)
meoghe
Member
29 Points
74 Posts
Re: Local Resources for multi language in MVC3
Dec 18, 2012 02:15 AM|LINK
sorry everybody, this is my mistake. I have not created Logins.resx.
thanks everybody for help,
so sorry