3

I want to find a way to force CSOM to always return values in en-us (1033 locale). For instance, when I'm trying to get ContentType Name using ContentType.get_name() I end up getting different results depending on the current UI language. This is very inconsistent and hard to work with. For instance, when the current lcid is set to 1049 ContentType Name for Folders is returned as 'Папка'. When it is set to 1033 - 'Folder' is returned. I want to find a way to explicitly retrieve items in en-us context, but can't find a way to do so.

Here is a code snippet, I'm using:

function retrieveListItems() {
           var clientContext = new SP.ClientContext("/");
        var oList = clientContext.get_web().get_lists().getByTitle('EnUsDocs');
        var camlQuery = SP.CamlQuery.createAllItemsQuery();// new SP.CamlQuery();
        SP.CamlQuery.createAllItemsQuery();
        this.collListItem = oList.getItems(camlQuery);
        clientContext.load(collListItem, 'Include(ContentType, ContentTypeId, Title, Editor, Author, ID)');
        clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));}

    function onQuerySucceeded(sender, args) {
        var listItemInfo = '';
        var listItemEnumerator = collListItem.getEnumerator();
        while (listItemEnumerator.moveNext()) {
            var oListItem = listItemEnumerator.get_current();
            var ContentType = oListItem.get_contentType();
            var name = ContentType.get_name();
            console.log(name);
        }

        //Outputs 'Folder' or 'Папка' Depending on the lcid parameter in cookies";
       console.log(listItemInfo);
    }

    function onQueryFailed(sender, args) {
        console.warn('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    } 

I have checked the difference in the Requests between UI languages with Fiddler. The only difference is in the cookie key 'lcid'. I was thinking about changing this cookie key from JavaScript, but this method will change my UI. Also, it seems a bit dirty.

1 Answer 1

6

I don't think it is possible. I hope someone can prove the opposite. What you can do is to map the results into your own objects in the client. I had a similar issue, when I wanted to use $filter query strings in the REST calls to the listdata.svc in SharePoint 2010. The problem is that the Display Names are used for the columns and are different for different locales.

Your user has 1049 (Russian) and gets "Папка" instead of "Folder"

While mapping you can get dinamically the property names by using ScriptResx.ashx

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

Res.folder corresponds the name of the "Папка" or "Folder"... So when you map you do it like this:

var myMappedObj = {};
myMappedObj.Folder = objFromServer[Res.Folder];
1
  • Thank you very much! This is a great solution. Mapping is absolutely fine with me. I've found an article in your block chuvash.eu/2012/02/13/scriptresx-ashx-in-sharepoint/ I wish I read it much earlier. _layouts/ScriptResx.ashx is a great trick I wasn't aware of. Commented Aug 12, 2013 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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