2

Assuming I can easily retrieve a string from the resouce file using this:

SPUtility.GetLocalizedString("$Resources:MyKey", "MyResources", (uint) CultureInfo.CurrentUICulture.LCID)

How can I loop through all resource string entries (key and value) of the current culture?

I want to do this because I want to transfer all resource strings to the client side using an ashx-handler. If there is a more elegant way, please let me know!

Thanks a lot!

3

Use the OOTB ScriptResx handler already in SharePoint, how is outlined here

Chuvash - ScriptResx in SharePoint and here Chuvash - Javascript localization in SharePoint

Basically you need to add something like this in your resx-files, to create a namespace for your resource

<resheader name="classFullName">
  <value>Takana.Res</value>
</resheader>

And then you can get the resources loaded on a page through the following

<script type="text/javascript"
src="/_layouts/ScriptResx.ashx?culture=" + L_Menu_LCID + "&name=Takana">
</script>

And access your resources in JS through var lang = Takana.Res.YourResourceStringKey;

  • Strange, googling for days and never stumbled upon this handler! But: Tried it and it unfortunately gives me an error 500. Tried with parameters, without, with correct name and lcid, on different site collection, server root, subsites. Always 500. – elsni Jul 26 '16 at 10:05
  • Should not give you a 500, have you tried with one of the built in resource files? like /_layouts/ScriptResx.ashx?culture=en-us&name=SP.Res? – Robert Lindgren Jul 26 '16 at 10:32
  • It works with built-in resource files! Thanks! Too bad it does not work with culture-invariant resource files, which was the cause for my 500 error – elsni Jul 26 '16 at 13:20
  • Ah, that's right, you need to have at least an 'en-us' one you can point at – Robert Lindgren Jul 26 '16 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.