For my first part I’ve chosen the sandboxed solution. This is the easiest to explain and resource path’s don’t apply here.

We will see later what we can do with MUI sandboxed.

Useful links

Lcid codes

Culture specific list

Ok let’s get starting:

  • Open visual studio Glimlach
  • Select empty SharePoint solution, fill in the url and select sandboxed
  • Create a folder and give the “Resources” as name

 

image

 

  • Now fill the resources directory as you can see above, first an invariant resource and after than culture specific resources (of course if you use different languages than shown be sure to use the correct culture specific code – between resource name and .resx)

image

  • if you build your solution already than you can see in the hidden bin folder that you have 3 language resource satellite assemblies
  • Next is to add these assemblies to your solution package
      • to do this you’ll have to select your solution package file and click on “Advanced” at the bottom of the window
      • Next click on “Add” and select the dll file of the language (for this example we’ll have to do this 3 times (en, fr and nl) but never select the debug directory outside of the development machine, if your solution goes to UAT or production than you’ll have to build the solution in “Release” mode and select those dll’s to add to the package. Never use debug build dll’s to add to your SharePoint solution.
      • as you can see in the print screen below, I’ve selected the dll from the en-US path in the release directory
      • in the “Location” text field you must add a prefix “en-US” to specify for which language the dll stands for.

 

image

 

image

 

  • In the example above you can see that the 3 resource files are added as assemblies.

List Definitions, List Instances, Feature titles and descriptions cannot be set in MUI because of the location of the resource files. Resource files via Sandbox are not stored in the 14 hive directories and thus cannot be used for Multi lingual names

However, if you separate the resource files and deploy them via a separate SharePoint farm solution (wsp) than you can use these files.

I’ve created a separate solution that will be deployed farm wide and contains the resource files in a mapped folder to the 14hiveresources but I gave the resource files the name “MuiSeries1”.

  • Ok, next up is to create the sandboxed webpart that we are going to use
      • purpose of the webpart is to have a sign up form where people give their score about a restaurant that they’ve visited.
      • and we will not be filling in the text fields of the labels because these has to be multilingual of course
      • We have 3 labels (name of the restaurant, score that people will give it and if the food was above/below or just average) , we cannot use encoded literals because they cannot be used in sandbox solutions Encodedliteral – MSDN
      • Now here you can decide to create a separate solution where only the 14 hive resources are being added or you can use the resource files as we’ve created them earlier. In the example that you can download I’ve added both solutions
      • There is one hitch in Sandbox solutions and that is, you cannot use text=”<%Resources:Name of resource file, name of key;” . Your code will not compile and you’ll receive the following error: “The name ‘InitializeControl’ does not exist in the current context” . So instead of putting this in the ascx file, we are going to fill in the labels via code.

image

 

      • So we leave the labels without the “Text” attribute and go into the code behind
        • First we set the label score to be filled in via the sandboxed resources (keep in mind that it’s best case to first add the key “Score Label” to the sandbox resource files, after that auto completion will do the rest)

image

        • Secondly we are going to use SPUtility.GetLocalizedString since this is also possible to use this in a sandbox solution. I’ve created a resourceHelper for this, it’s nothing more than 2 static methods
          • in the first method the language LCID is being retrieved and via an override mechanism the second method is called

image

      • After adding the resourcehelper.cs you can now get the MUI labels as well via the helper

image

 

After this, just deploy the solutions and you’re done. I’ve also added some extra functionality in the webpart, like some multilingual dropdown values Glimlach . Download Code –> click file and download original

Next blog will be about feature resource files… (which you can use in Sandbox as well Glimlach )

Hey everyone

I don’t know how many of you already noticed 2 properties on the feature that has something to do with resources.

Given that I want to create a complete A-Z guide concerning MUI in SharePoint, I’m going to explain these 2 properties in detail.

 

image

 

There are 6 locations where the resource files can be stored, but today we are going to focus on:

  1. feature resources: <hive>14TEMPLATEFEATURES<feature>Resources
  2. 14 hive resources: <hive>14Resources

 

Default Resource File:

 

image

 

As you can see I have Feature resource files in the “VisualWP” feature. But I also have “MuiResource” files in the “Resources” mapped folder to the 14 hiveResources .

Now the default resource file option on the feature is a sort of overruling mechanism. If the feature resource files are outdated or no longer displaying the correct text (or any excuse that you can give to it) than the redirect will happen to the 14 hive resource files. So if you have “VisualWPFeatureTitle” and “VisualWPFeatureDescription” in your feature resources and in 14 hive resource files than an overrule will happen and the values from  the 14 hive resources will be used in the appropriate language. The feature resources will be ignored.

Also no mix mode is possible, if you only want to use the title from the 14 hive resource files and the description from the feature resources than this isn’t possible.

So why would you want to do this?

If you want to use the resource values on more than 1 location (across web applications for example) than this is a possibility. So you have your feature resource files deployed but you want to use the same resource values in a totally different solution. A problem will come up because you cannot get to the values in the feature resource file. So you’ll have to deploy the same key/values in a 14 hive resource file. Meaning duplication of data, which is never good Glimlach .

So it’s best to override the feature resource files to the 14hive resource files and keep all the key/values in 1 location.

This option adds an argument in the xml structure of the xml file as shown below.

 

image

Require resources:

This option is a Boolean value meaning only true or false can be entered.

By default this option is set to false.

What this does is checking if the feature has feature resource files, if yes than the feature will be displayed in the features list. If a feature resource language file isn’t located that the feature will not be shown in the list. This is designed to prevent a feature from being displayed with the ugly “$Resources:FeatureTitle;” notation when a language resource file cannot be found.

Note that overruling the resource files in the previous option is not sufficient.

The feature resource files must exist, but they can be empty though.

Only than the system will get the values from the 14 hive resource files and will be shown in the features list of site.

 

Next up Part 1 of the MUI series.

Yesterday I gave a presentation about Deep dive MUI and in my presentation I’ve asked some questions to the audience. One of those questions was: What if you only need 1 language?

First I’ll set the scene for this question so you’ll understand the purpose of the question.

MUI uses a lot of resources at certain locations, but in aspx code there are small differences in coding.

Most developers will write the code like below.

Asp with text Welcome

But, as you can see the code below, it’s almost exactly the same (with a MUI twist).

Asp with resources

In the second print screen I’m using a resources file named “RestaurantResource” and I’m asking for the value of the key “FormTitle”.

Now if I have “RestaurantResource.fr-FR.resx” and “RestaurantResource.nl-NL.resx” in that resource directory as well, than I will be given the Dutch or French text. Depending on the language selection of the user the value will be given in that language.

So this is all for MUI, but what if only 1 language is asked?

Isn’t it best to still write the second print screen instead of the first and to use resource files?

It offers some very nice benefits:

  1. Only 1 location to check the values, if one value must be changed a small effort is needed
  2. If the client asks if it is possible to have the same labels in multilingual… No problem, only add 2 resources files and all is done
  3. You don’t need a lot of time of refactoring
  4. Saves you a lot of time as well

In addition to all this, you can also use the SharePoint control for displaying text.

SharePoint:EncodedLiteral

This gives you the benefit if you client wants to add some HTML code to display the text, it’s possible without refactoring, if you display regular text than it’s no problem as well. But you are ready for any future changes in text value.

Resources

Of course this from my own point of view and making sure you are developing with the max coverage for future changes.

Tell me what your point of view is on this in the comments. Or if the message is too big, feel free to send me a mail 🙂

hey everyone

Yesterday I gave a presentation about MUI in SharePoint 2010. I had a good time and the audience was great.. Lots of presents were given, if the answer was correct ofcourse…

The slidedeck will also be uploaded to the new BiWUG site early next year, but in the meanwhile you can download them from here as well. Mui-Deepdive.pptx

Feel free to use slides for your own presentations.. Also if you have questions, leave a comment and I’ll reply asap..

I’m also going to write out all the demo’s in a MUI blog series.., Adam Burcher has already done the same SharePoint Baker . But I’ll be giving my meligo twist on it 🙂 .

If you were at the session, thanks for coming and I hope you have learned something..

Have a nice day