【问题标题】:How to view translated county in OctoberCMS rainlab.location plugin如何查看十月翻译的县CMS rainlab.location 插件
【发布时间】:2019-02-26 23:34:36
【问题描述】:

我已经安装了rainlab.location 和rainlab.translate 插件。我在后端翻译了国家和州,但我无法在前端查看它们的翻译。这是我正在使用的代码(来自文档):

 {% set countryId = countryId|default(form_value('country_id')) %}
 {% set stateId = stateId|default(form_value('state_id')) %}

 <div class="form-group">
 <label for="accountCountry">Country</label>
 {{ form_select_country('country_id', countryId, {
    id: 'accountCountry',
    class: 'form-control',
    emptyOption: '',
    'data-request': 'onInit',
    'data-request-update': {
        'country-state': '#partialCountryState'
    }
  }) }}
 </div>

 <div class="form-group">
 <label for="accountState">State</label>
 {{ form_select_state('state_id', countryId, stateId, {
    id: 'accountState',
    class: 'form-control',
    emptyOption: ''
 }) }}
 </div>

即使我切换了语言,它也以英语显示国家和州!

【问题讨论】:

    标签: octobercms octobercms-plugins


    【解决方案1】:

    可能问题在于检索记录

    https://github.com/rainlab/location-plugin/blob/master/models/Country.php#L71

    当我们直接使用-&gt;lists('name', 'id');调用时,翻译关系没有加载。

    但是如果你从

    改变这一行
    return self::$nameList = self::isEnabled()
         ->orderBy('is_pinned', 'desc')->lists('name', 'id');
    

    return self::$nameList = self::isEnabled()
         ->orderBy('is_pinned', 'desc')->get()->lists('name', 'id');
                                    ----- ^ <- this one
    

    它加载翻译关系并且工作正常。

    现在你可以在本地更改它应该可以工作,将来他们可能会解决它。

    如果您担心插件更新,那么您可以提取该功能并实现您自己的功能。

    它只是form_select_country twig function,您可以将其添加到您自己的不同名称的插件中,以使其工作,因为您看到只有小代码要复制:)

    https://octobercms.com/docs/plugin/registration#extending-twig

    如有任何疑问,请发表评论。

    【讨论】:

    • 但是@HardikSatasiya 如果此插件得到更新,那么您的更改将会丢失。
    • 我也这么认为.. @Hardik,这是否可以创建我们的自定义插件来通过创建挂钩或其他东西来进行这些修改?
    • 为什么不只是 form_select_country twig 函数,您可以将其添加到您自己的插件中,并使用 diff 名称使其工作,因为您看到只需复制小代码 :)
    猜你喜欢
    • 2018-08-09
    • 2017-06-10
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    相关资源
    最近更新 更多