Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to replace one word in my SharePoint site, depend in on that what language is used. I found this question: Get the current UI language with ECMAScript

I tried to use that code and it works only, if I add it into script editor and my page is in edit mode. If I try to add it to master page, it won't work. If I add it to external js-file, it won't work:

Firebug gives error message:

"SP.Res is undefined"

Master page code: ExecuteOrDelayUntilScriptLoaded("multilanguage.js", "sp.js")

If I try to use other solution (same link, last post), Firebug gives error message:

"ReferenceError: g_wsaLCID is not defined"

"var lcid = g_wsaLCID;"

My example code:

<script type="text/javascript">
var lcid = SP.Res.lcid;

if(lcid == "1033")
{
    alert('English'); /* Works only, if it in script editor and page is in edit mode */
}
</script>

What I'm doing wrong? How I can get it to work? Why it is working only script editor and page is edit mode?

share|improve this question
    
SP 2010 or 2013? –  Robert Lindgren Apr 8 at 9:20
    
SharePoint 2013 –  user20968 Apr 8 at 9:28
add comment

1 Answer

up vote 0 down vote accepted

You should not use the file name in ExecuteOrDelayUntilScriptLoaded. but the function you want to trigger. Try this in your masterpage (2010)

ExecuteOrDelayUntilScriptLoaded(function(){
    var lcid = SP.Res.lcid;

    if(lcid == "1033")
    {
        alert('English'); /* Works only, if it in script editor and page is in edit mode */
    }
}, "sp.js")
share|improve this answer
    
Thank you! It works also SP 2013. What if I want to use external js-file? –  user20968 Apr 8 at 9:32
    
If you want to use an external js file you need to make it SP.SOD compatible, more here: ilovesharepoint.com/2010/08/… –  Robert Lindgren Apr 8 at 9:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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