简体   繁体   中英

Locomotive CMS - Access to translations data

I'm using locomotive CMS and I want to translate some strings. I have the following data in a my tanslations.yml file :

  general: 
    404: 
      title: 
        en: "404 Page Not Found"
        fr: "404 - Page non trouvée"
        de: "404 Seite nicht gefunden"
        es: "404 Página no encontrada"
        pt-BR: "404 Página não encontrada"

      subtext_html: 
        en: 'The page you requested does not exist. Click <a href=\"/collections/all\">here</a> to continue shopping.'
        fr: "Cette page n'est pas disponible. <a href= '/collections/all'>Retourner au magasin</a>"
        de: 'Die von Ihnen angeforderte Seite existiert nicht. Klicken Sie <a href=\"/collections/all\">hier</a>, um den Einkauf fortzusetzen.'
        es: 'La página que ha solicitado no existe. Haga clic <a href=\"/collections/all\">aquí</a> para continuar la compra.'
        pt-BR: 'A página que você solicitou não existe. Clique <a href=\"/collections/all\">aqui</a> para voltar às compras.'

And I can't have access to this data in my 404.liquid page:

---
title: Page not found
published: false
---
{% extends theme %}
    {% block 'content' %}
        {{ 'general.404.title' | translate }}
        {{ 'general.404.subtext_html' | t }}
    {% endblock %}

In locomotive/mounter/translation.rb file there is just 2 fields: key and values

module Locomotive
  module Mounter
    module Models

      class Translation < Base

        ## fields ##
        field :key
        field :values

        ## methods ##

        def get(locale)
          self.values[locale.to_s]
        end

        def to_params
          { key: self.key, values: self.values }
        end

        def to_s
          "Translation #{self.key} (#{self.values.keys.join(', ')})"
        end

      end
    end
  end
end

Does this mean that we can't structure translations data like this?

Nope. From the official page:

In LocomotiveCMS, you need to have a separate template for each locale. Create a new 404 template for the Japanese localization named app/views/pages/404.ja.liquid and paste in the following contents.

---
title: お探しのページが見つかりません
published: true
---
{% extends 'index' %}

{% block 'main' %}
  <p>
    申し訳ありません。そのページは存在しません。
  </p>
{% endblock %}

You can check the whole tutorial here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM