是的,您是对的 SCA 开箱即用没有此功能,但是您可以在 url 中发送“lang”参数并且可以更改您的语言。
请记住,如果您使用的是 SCA 视觉版本,请不要在设置选项卡下的配置中添加任何语言主机
传递“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() 中使用以下代码将一些数据返回到把手视图
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
};
}
- 在下面的文件 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}}
- 完毕!!现在你可以看到 'lang' 参数被添加到 url
如果您需要更多帮助,请告诉我。