Last post Feb 23, 2007 11:31 AM by amit333
Feb 16, 2007 10:19 AM|amit333|LINK
I am working on ASP.NET 2.0 project. We are using using branding in our project, in other words we need to have 2 different sites using the same code base, has similar functionality but different look and feel and different "Text messages/labels" etc.
I am planning to use themes and load different themes dynamically based on the brand to take care of the look and feel and the labels/messages etc. Now we are planning to implemet localization in our sites. I know how implicit and explicit localization works
but I am not sure how can I make use of that in this situation. In the local resource files I can hard code the labels/messages for one brand but not others and If I create different resource files for both brands, how will this be taken care at runtime?
Any idea ???
Let me know if you need more information.
Feb 18, 2007 07:02 AM|vivek_iit|LINK
The ASP.NET runtime will take care of loading the appropriate reosurce files based on the Culture of the current thread. See this article for details:
Hope this helps,
Feb 19, 2007 02:22 PM|amit333|LINK
This will work if I have only 1 site but not with 2 sites. Let me explain more:
We are using Web Application approch, not web site approach. We have 2 sites using the same code base, same project files etc etc.
Lets say I have default.aspx page in my project, both the sites will use this page, now when I Generate Local Resoruce file for this page, it will generate 1 Local resource file and that can be used by 1 site. But I need to have 2 resource files for 2 sites
for the same defualt.aspx page because both the sites have similar functionality but different look and feel and different labels so the resource and the skin files has to be different for these 2 sites.
So basically all the pages in this project will be used between 2 sites but they need to have different resource files...
Now my question is how can I have 2 local resource files for the same .aspx page and for the same language. I Think its is not possible not sure though.
Is there any way to accomplish this?
Feb 19, 2007 02:42 PM|vivek_iit|LINK
The beauty of resource files and themes is that you *don't* need to create two separate sites. Resource files and themes will do the work in one site only, saving you valuable time and efforts.
If you have already made two sites, then you do need to create resource files on each site, or use a commond database storing all that info. If you want resource files only for lables and text, then you should use the themese and skins for that site only,
why you want to go for reosurce files (since you already have another different set of same pages in the second site)?
Feb 19, 2007 03:14 PM|amit333|LINK
We have to have 2 completly different sites(in IIS but the code base or the project is still the same, 2 IIS websites pointing to the same doe base.).
Ex: a automobile company owns 2 different brands of car.
Both the brands have to be different sites but the functionality on both the sites would be same, so instead of having seperate code base we have same code base but we were using different look as feel on both the sites. As I mentioned that I can control
look and feel by loading different themes but for labels I would need resource files... because I need to have localization for both the sites.
so in other words, 1 .aspx page in this project needs to have 2 resource files(for 2 sites) for each language. I dont think I can do this just with themes, because themes will provide different labels for different sites but it can not provide localization.
Hope it is clear now?
Feb 19, 2007 11:51 PM|vivek_iit|LINK
So you have the same code base, that's good. I was thrown off when you said that you are using Website model and have two sites.
Now my first reply to your original post is still applicable. Let me explain: you will create mulitple resource files inside your single project. All these resource files will contain different values for the same set of indentifiers (like label names),
so that in one resource file you might have English text as the Label caption whereas you might have Hindi Unicode text in another resx file for the same label caption.
The resource file to be loaded will be decided by the locale of the current thread. So as soon as you change the culture of the current thread, you will be able to access resources for that specific culture automatically (the runtime does the work for you).
See my article (link in the first post) for a working sample of the same.
Hope this helps,
Feb 20, 2007 10:01 AM|amit333|LINK
Actually, I said we are NOT using website model.
let me explain, what I am looking for, in more detail:
I have same code base for 2 IIS web sites, lets say site A and site B. both sites access same default.aspx.
This default.aspx has label control "lblText" and the value of this label would be different for 2 sites. Let say, on site A the label text is "Hello World" and on site B the text is "Welcome" and similarly when the site is loaded in french then the Site
A needs to should show equivalent of "Hello world" in French and site B should show equivalent of "Welcome" in French.
if Site = "A" lblText.Text = "Hello World"
else if Site = "B" lblText.Text = "Welcome"
I can take care of the above logic by using Themes(load different themes based for Site A and Site B) but when it comes to localization, I will still need language conversion for both site, or in other words I would need 2 local resource files(for site A
and B) in french for same default.aspx page, which I know is not possible, but I am just looking for some work around to do the same)
I hope I am more clear this time?
Feb 21, 2007 01:16 AM|vivek_iit|LINK
Thanks for the detailed explanation, it made things clear. So the issue is that you need to load different texts (localized) according to the website.
This can be done by having a single resource file which has multiple values for the same label. For e.g:
SiteAlblText.Text = "Welcome"
SiteBlblText.Text = "Hello"
Here SiteA and SiteB can be identifiers which you can set at the application level in some base page class by capturing the application name from the Request object. Then you need to set the label values in code-behind by calling ResourceManager.GetResources(key)
where key would be SiteName(from request) +lblText.Text.
There can be other ways to achieve this in a similar fashion.
Feb 22, 2007 04:36 PM|amit333|LINK
That definately helps but this is more like using the Localization approach used in ASP 1.0, where we have to use resource manager.
I am being lazy :) and I am trying to find out some way where it can be done without writting any code, just like the way Local resource file works in ASP.Net 2.0.
I wont be surprised if there is no way of doing that automatically and I will have to write the code to set the value dynamically for each localized control.
Let me konw if you can help more on the same. Thanks for your help so far.
Feb 23, 2007 12:49 AM|vivek_iit|LINK
The issue is that you want two different values for the same label under same culture. So this isn't exactly localization but customization and hence you will need to code it manually.
One thing which you can try ( am not sure if it will work 100% as you want) is to write your own defined "culture" and create separate resource files for it. This
culture will not be a real culture but needed just for the other set of values for same controls. Based on the current website you can change the locale of the current thread to either use your own new culture or any other.
This link might help:
Feb 23, 2007 11:31 AM|amit333|LINK
I will try the custom cultures and see if it works for us, if not then will probabaly go with otehr approach where I will have code it manually.
I appreciate all your help.