MUI Blog series (part 1) Sandboxed?

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 )

Leave a Reply

Your email address will not be published. Required fields are marked *