From: http://tomblog.insomniacminds.com/tag/sharepoint/
In a country where English is not the native tongue, localisation can be pretty important. localisation within SharePoint is achieved by using resources and resource files. although the use of resources is not mandatory, it's usually good practice to use them anyway. you don't want to hard code strings in your application, and, moreover, you never know when your application shocould be localized. setting up and using these resources in SharePoint can be quite confusing. so here is a little article covering this topic.
Resources
Resources-in this case: strings-are contained within XML based. resx files. every resource in such a file is identified by a fixed name. (quite like a HashTable) Here is a little example.
<root>
<data name="FieldManagerPageDescription">
<value>Manage the field of this application.</value>
</data>
</root>
For every new localization, you need a new. resx file with the same names as keys. you can just copy the original. resx file to achieve this quickly. in this new resource file you translate the original values within the value tag. the new resource file has to be named as follows: <original_name>. <culture>. resx.
Eg.-myresource. resx
-Myresource. en-US.resx
-Myresource. fr-FR.resx
SharePoint & Resources
First thing you need to know, SharePoint defines two kinds of Resource files: Application resources and Provisioning resources.Application resourcesAre resources used within the normal execution of the SharePoint application. normal SharePoint execution include: Application Pages, Web Parts and Controls. sharePoint also makes a difference between application resources used in normal web applications and application resources used in the central administration. don't forget that.Provisioning resources, On the other hand, are used when provisioning elements, so you have to use them within features, site definitions and list definitions. OK, now let's see the practical side of it: deployment and usage.
1. Deployment
Resource files in SharePoint are located in different folders. Here is a list:
- C: \ Inetpub \ wwwroot \ wss \ VirtualDirectories \ <port> \ App_GlobalResources \
- <Hive> \ 12 \ Resources \
- <Hive> \ 12 \ CONFIG \ Resources \
- <Hive> \ 12 \ CONFIG \ AdminResources \
- <Hive> \ 12 \ TEMPLATE \ FEATURES \ <feature> \ Resources \
So, how do you know where to put your resource files? Well, every type of resource has its own folders.
Provisioning resources
- <Hive> \ 12 \ TEMPLATE \ FEATURES \ <feature> \ Resources. <culture>. resx
- <Hive> \ 12 \ TEMPLATE \ FEATURES \ <feature> \ Resources \
- <Hive> \ 12 \ Resources \
Every feature uses the resources file located in its Resources folder. you can however use another resource file or even share resources. to share resource files you have to put them in the 12 \ Resources \ folder. site definitions and list definitions also get their resources from this folder.
Application resources
- <Hive> \ 12 \ CONFIG \ Resources \
- C: \ Inetpub \ wwwroot \ wss \ VirtualDirectories \ <port> \ App_GlobalResources \
Application resources are located in CONFIG \ Resources folder. for a web application to use those resources, they have to be copied to their App_GlobalResources folder. (each web application has its own Global Resources folder) How is this done? At creation of the web application, the resources are initially copied to the App_GlobalResources folder. When adding new resources to the CONFIG \ Resources folder, the resources have to be copied to existing web applications.You can do this manually or use the STSADM command: copyappbincontent.Application resources: admin
- <Hive> \ 12 \ CONFIG \ AdminResources \
- C: \ Inetpub \ wwwroot \ wss \ VirtualDirectories \ <port> \ App_GlobalResources \
Application resources for the central administration work the same way as normal application resources, doesn't that the base folder is CONFIG \ AdminResources.
2. Usage
This last part will focus on how to use resources within SharePoint elements. Luckily it doesn' t really matter which kind of resource you are using. Here are the different ways:
In C #:
HttpContext.GetGlobalResourceObject("MyResource", "MyName").ToString();
In ASPX properties:
<%$Resources:MyResource, MyName%>
In ASPX as text:
<asp:literal runat="server" Text="<%$Resources:MyResource, MyName%>" />
In XML:
$Resources:MyResource, MyName
In XML features, using the default resource file:
$Resources:MyName
3. Conclusion
There you go. Everything you will ever want to know about resources in SharePoint.
Part of this article is derived from the excellent article of Mikhail Dikov. you can consider this article as some sort of extension of his article. be sure to read it. also, I 'd like to thank Tom Verhelst for the heads up on the copyappbincontent. thanks man!
Have a great week!