NetSuite的SuiteCommerce Advance:使用单个域(无主机)自定义多语言?

时间:2017-03-15 08:21:55

标签: subdomain netsuite suitecommerce

在SuiteCommerce Advance Vision中,默认情况下,设置多语言的行为是在设置下添加多个域 - >配置 - >多域标签 - >主机

设置完成后,您可以在网上商店中看到下拉列表,其中包含与该域相关联的域和语言。我们已经实现了这个功能。

但是,SCA还具有使用' lang'设置多语言的功能。参数将自动更改单个域的语言,如下所示

We did this already-->(With multiple domain)
https://www.en.scasite.com/
https://www.fr.scasite.com/


We want below setup-->

https://www.scasite.com/?lang=en_US
https://www.scasite.com/?lang=fr_FR

那么,任何人都可以知道如何在url中传递语言参数吗?

1 个答案:

答案 0 :(得分:1)

是的,你是对的SCA开箱即可没有这个功能,但是你可以发送' lang'网址中的param,可以更改您的语言。

请记住,如果您正在使用SCA视觉发布,请不要在设置选项卡下的配置中添加任何语言主机

通过' lang' param,即www.domain.com/lang=it_IT等

覆盖自定义模块中的主机选择器文件以执行此操作,您需要在全局视图下创建以下两个文件

1.Modules/custom/GlobalViews@1.0.0/JavaScript/GlobalViews.HostSelector.View.js 复制&粘贴在setLanguage中的代码下面:function(e){}

,   setLanguage: function (e)
    {
                var language_code = jQuery(e.target).val()
            ,   selected_language = _.find(SC.ENVIRONMENT.availableLanguages, function (language)
                {
                    return language.locale === language_code;

                });

        // We use the param **"cur"** to pass this to the ssp environment
        var current_search = Utils.parseUrlOptions(window.location.search);

        // if we are in a facet result we will remove all facets and navigate to the default search
        // TODO REVIEW THIS
        if (window.location.hash !== '' && _.values(SC._applications)[0].getLayout().currentView instanceof BrowseView)
        {
            window.location.hash = Configuration.defaultSearchUrl || '';
        }
        current_search.lang = selected_language.locale;

        window.location.search = _.reduce(current_search, function (memo, val, name)
        {
            return val ? memo + name + '=' + val + '&' : memo;
        }, '?');

    }

在getContext()中使用以下代码将一些数据返回到handlbar视图

var available_languages = _.map(SC.ENVIRONMENT.availableLanguages, function(language)
        {
            // @class GlobalViews.CurrencySelector.View.Context.Currency
            return {
                // @property {String} code
                code: language.locale
                // @property {String} internalId
            ,   internalId: language.internalid
                // @property {String} isDefault
            ,   isDefault: language.isdefault
                // @property {String} symbol
            ,   symbol: language.languagename
                // @property {String} displayName
            ,   displayName: language.locale|| language.locale

            , isSelected: SC.ENVIRONMENT.currentLanguage.locale === language.locale

            };
        });

        // @class GlobalViews.CurrencySelector.View.Context
        return {
            // @property {Boolean} showCurrencySelector
            showLanguageSelector: !!(SC.ENVIRONMENT.availableLanguages && SC.ENVIRONMENT.availableLanguages.length > 1)
            // @property {Array<GlobalViews.CurrencySelector.View.Context.Currency>} availableCurrencies
        ,    availableLanguages: available_languages || []
            // @property {String} currentCurrencyCode
            // @property {String} currentCurrencySymbol
        ,   currentLanguageSymbol: SC.getSessionInfo('language').languagename
        };
    }
  1. 复制&amp;粘贴以下文件中的代码 Modules/custom/GlobalViews@1.0.0/Templates/global_views_host_selector.tpl
  2. &#13;
    &#13;
        {{#if showLanguageSelector}}
        	<div class="global-views-currency-selector">
        		<span class="global-views-host-selector-addon">
        			{{currentLanguageSymbol}}
        		</span>
        		<select data-toggle="currency-selector" class="global-views-currency-selector-select">
        			{{#each availableLanguages}}
        				<option value="{{code}}" {{#if isSelected}}selected{{/if}}>
        					{{symbol}}
        				</option>
        			{{/each}}
        		</select>
        	</div>
        {{/if}}
    &#13;
    &#13;
    &#13;

    1. 完成!现在你可以看到&#39; lang&#39; param正被添加到url中
    2. 如果您需要更多帮助,请与我们联系。