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

NetSuite's SuiteCommerce Advance: Customize Multi Language With Single Domain(Without Hosts)?

在 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 中传递语言参数吗?

是的,你是对的,开箱即用的 SCA 没有这个功能,但是是的,你可以在 url 中发送 'lang' 参数,并且可以更改你的语言。

请记住,如果您使用的是 SCA vision release,请不要在设置选项卡下的配置中添加任何语言主机

传递'lang'参数即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() 中使用以下代码 return 一些数据到 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. 将下面的代码复制并粘贴到下面的文件中 Modules/custom/GlobalViews@1.0.0/Templates/global_views_host_selector.tpl

    {{#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}}

  1. 完成!!现在你可以看到 'lang' 参数被添加到 url

如果您需要更多帮助,请告诉我。