Skip to main content

Implementation of Simple Copies inside POWR repo

What is Simple Copies​

Our Simple Copies is way how we store translated strings for text.

We store it on a strapi content manager to upload, change data without knowing the code

old cms

new cms

Downloading Simple Copies​

While building with docker, we get these simple copies by API in deployment/fetch_simple_copies.js from strapi and store them in yml files by locales.

Backend part of implementation​

  • /Users/ranger/dev/powr/app/helpers/switchboard_helper.rb we get simple copies by name from I18n gem. here is the full description

  • Here /Users/ranger/dev/powr/config/application.rb loads all simple copies for I18n in this line of code:

    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', 'copies-from-strapi', '*.yml').to_s]

Fronted part of implementation​

  • The app/helpers/switchboard_helper.rb gets all the simple copies from the yml files that are stored in config/locales/copies-from-strapi, parses them into JSON as a flat hash and then app/helpers/simple_copy_helper.rb loads them into a view inside window.SIMPLE_COPIES_DICTIONARY.

  • If you want to add some new root key to load in the js part, for example example.test, example is the (root key), you need to go to app/helpers/simple_copy_helper.rb and inside simple_copies_dictionary you can add this line to upload simple copies that from your root key

simple_copies.merge!(copies_from_yaml("example"))