Last post Mar 26, 2007 12:05 PM by degt
Mar 25, 2007 08:52 AM|degt|LINK
OK I think I have stumbled on a localization system problem. I understand that the peer App_LocalResources is where I should store resource files used by the pages in that directory (or subfolder).
I also understand that the App_GlobalResources is used for placing global resource files. So far so good. I also know how to use the Localize asp control as well as referring to the resource fetch on the Text property with both implicit and explicit forms.
That being said, my site makes use of Master Pages and because these are what they are I decided to place the localized text of the master pages in the App_GlobalResources directory. Because a Master Page is not really a page I know (?) that I can't use
MasterPage and expect it to be found by the resource fetcher.
So, to circumvent that I decided to use the explicit form in which I name the resource file as in
Text="<%$ Resources:MasterPage,HeaderTop %>"
That works fine as long as the page using the Master Page is in the root folder of the application but as soon as the browser requests a page in a subfolder that makes use of the same Master Page the localization "breaks" and the default language is shown.
I think it would be a waste of space and time to have to multiplicate this same strings in App_LocalResources folders when they are really only being used in the Master Page.
localization master subfolder
Mar 25, 2007 05:57 PM|michielvoo|LINK
you don't have to repeat the same strings for all pages using the masterpage. You can create an App_LocalResources folder in the same folder as the masterpage. So the first line of your post is correct, store the resource files along with the masterpage,
never mind that it is not 'really' a page, it will work just the same. MasterPage is actually a UserControl!
Mar 26, 2007 05:28 AM|degt|LINK
OK, I have moved both the MasterPage.resx and MasterPage.es.resx files (my master page is named MasterPage.master) to the App_LocalResources directory located on the same level as the Master page
+ root folder
In these resource files I have the following keys (value is not shown here): HeaderTop, FooterQuestions, FooterContactUs
Since I cannot use the @Page directive on a master page I cannot use the meta:resourcekey="MasterPage" at the "page" level so I am still using it on the server controls. But now I get problems saying that the "resource object with key 'NAME HERE" was not
I tried both using the same notation as in the original post and also replacing that Text property in the Localize control with meta:resourcekey="HeaderTop"
It just can't find those resources anymore.
Mar 26, 2007 05:52 AM|degt|LINK
OK, I had missed a quotation mark so now the Web Express does not give errors about the "object with key .... was not found". I can rebuild the solution without those errors (or any other errors for that matter).
But my resources are not being used for some reason. I set my Language browser settings so that Spanish is on top of the list followed by English to make sure that the resources are being used. But those that are defined in the MasterPage resource are simply
So in the MasterPage.*.resx I have (simplified, showing the translated resource only):
HeaderTop.Text "texto de encabezado"
FooterQuestions.Text "Alguna pregunta?"
And on the MasterPage.master I have the following:
But the resources are still shown on the page in the default language. In the same master page I have another resource which is in a separate file in the App_GlobalResources directory and I refer to that resource in the explicit format (including the filename)
and that one appears in the correct language setting (Spanish in this case), but like I said it only works if the page using the resource is in the top level directory and not in a subdirectory (that is the problem we were trying to solve originally)
Any ideas how to get those working? I have read those localization quick starts over and over already and can't find what is wrong with it.
Mar 26, 2007 11:19 AM|michielvoo|LINK
please rename the resource files to:
So using the full filename including the file extension.
Does that work?
Mar 26, 2007 11:49 AM|degt|LINK
Renaming the resources to MasterPage.master.*.resx does indeed solves the problem of the items not being translated on the master page.
However, that works only for pages that inherit from that master page and are located on the root folder which is where the MasterPage.master.*resx are located in their App_LocalResources. IF the page that derives from that master page
is located in a subdirectory/subfolder then the items revert back to English.
Isn't that a bug? I mean, ASP.NET knows those resources are from the master page and where that master page is defined and therefore it should look for those resources on the App_LocalResources directory of THAT master page and then deal with the resources
defined in the derived page (.aspx) at the subdirectory level.
And as I mentioned before I tried using the explicit method but the problem there is that the root folder of my development machine is /MyApplication whereas on the webhost it is truly the root folder (/).
Any other ideas?
Mar 26, 2007 12:05 PM|degt|LINK
Please disregard the previous reply of 5:49PM as there was a small omission in my markup that led me to the wrong conclusion.
It works now, thanks a MILLION.