Gravatar for jpdery@coveo.com

Question by jpdery, May 19, 2014 3:08 PM

How to activate localization

I followed instruction https://developers.coveo.com/display/JsSearch/Localization and added french resources, but how to specify my interface to use those?

2 Replies
Gravatar for mlaporte@coveo.com

Answer by Martin Laporte, May 20, 2014 4:03 AM

Well in theory you only need to load the fr.js file after the JS UI libs to have the UI display in french. Just tried it in my setup, seems to work OK. The key line in the file is this:

String["locale"] = "fr";

That's what sets the current locale for translated strings. Changing this value should change the languages. There is also the Globalize library to initialize, which is done with this code:

Globalize.culture("fr");

(both those lines are present in fr.js).

Keep in mind the stock translations are only for the strings built-in the library, not the ones present in the HTML page (you can add strings and use them there if you want --- just added a sample to the doc page).

Can you check in your Chrome DevTools that the fr.js file is indeed properly loaded?

Gravatar for jpdery@coveo.com

Comment by jpdery, May 20, 2014 7:50 AM

code 18. (invalid urls, did not update the sample). But, I got this now:

Uncaught # CoveoJsSearch.WithDependencies.js:15380 Assert.failureHandler CoveoJsSearch.WithDependencies.js:15380 Assert.fail CoveoJsSearch.WithDependencies.js:15304 Assert.check CoveoJsSearch.WithDependencies.js:15309 Assert.exists CoveoJsSearch.WithDependencies.js:15330 TemplateCache.getTemplate CoveoJsSearch.WithDependencies.js:17343 …

Gravatar for jpdery@coveo.com

Comment by jpdery, May 20, 2014 7:51 AM

(above error does not occur if I dont reference localization files)

Gravatar for jpdery@coveo.com

Comment by jpdery, May 20, 2014 7:55 AM

(and which Url to use when in Salesforce context? I cannot just use /js/… right?)

Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, May 20, 2014 8:49 AM

In Salesforce, the CoveoJsSearch component should auto-load the appropriate file for the current user culture. But yeah, you need to do some magic to get the proper uri. It looks like this in a VisualForce page (disclaimer: haven't tested):

<apex:includeScript value="{!URLFOR($Resource.CoveoSolutions__CoveoJsSearch, 'js/cultures/fr.js')}"/>
Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, May 20, 2014 8:50 AM

About your error, enable break on error in the Script tag, and look at the callstack. That should give you more info about the cause of the failure. I see getTemplate which is totally related to localization, so I'm intrigued.

Gravatar for jpdery@coveo.com

Comment by jpdery, May 21, 2014 8:41 PM

This worked for me in Salesforce:

<apex:page >
    <CoveoSolutions:CoveoJsSearch stylesheet="CoveoFullSearch.css" /> 
    <apex:includeScript value="{!URLFOR($Resource.CoveoSolutions__CoveoJsSearch, 'js/cultures/fr.js')}"/>
    ...
    <script type="text/javascript">
        $(function () {
            String["locale"] = "fr";
            ....
        });

The preconditionfailedexception mentioned was not under Salesforce and I did not pursue the investigation.

Gravatar for dan@getfishtank.ca

Answer by Dan Cruickshank, May 19, 2014 5:31 PM

TL:DR; Check your value of Globalize.cultureSelector. Unless you've set it explicitly, it's likely set to "en" still.

English is set as the default in the Coveo.WithDependencies.js file and even though you're loading French it won't naturally take over as the default.

I'm still on the April release but I saw this code in the coveo w/ dependencies file. English is still loaded as the "default" culture in the file.

Globalize.cultures[ "default" ].calendar = Globalize.cultures[ "default" ].calendars.standard;
Globalize.cultures.en = Globalize.cultures[ "default" ];
Globalize.cultureSelector = "en";

And Globalize is a global variable so I'd try setting fr directly:

Globize.cultureSelector = "fr";

Also inside of CoveoJsSearch.js I'm never seeing the culture passed in directly when resolving culture-specific text. So when name is undefined (and it will be) it uses the this.cultureSelector value.

Globalize.findClosestCulture = function( name ) {
    var match;
    if ( !name ) {
        return this.findClosestCulture( this.cultureSelector ) || this.cultures[ "default" ];
    ...

This all a bit of a guess, ha.

Ask a question