Global Translations

This feature is intended for a small number of frequently used translations.

Please use it sparingly, because these keys are sent to every component.

Adding too many translations will unnecessarily slow down rendering.

Within config/svelte_on_rails.yml you can define global translations.

to_svelte_props:
  translations:
    helpers:
      submit:
        - create
        - update
        - submit
# Theese keys must match with the keys in config/locales.
# If set, the key _translations will be added by the to_svelte helper to the props

global_props:
  translations:
    any:
      - translations
# Theese keys must match with the keys in config/locales.
# If set, the key _translations will be added by the svelte view helper to the props of any component

to_svelte_props Example

config/locales/de.yml

de:
  helpers:
    submit:
      create: "%{model} erstellen"

With configuration like above

@book.to_svelte(:genre)
# => When genre is a associaton
# {
#   "genre" => "fiction", 
#   "_schema" => {
#     "genre" => {
#       "label" => "...", 
#   "_translations" => {
#     "helpers" => {
#       "submit" => {
#         "create" => "Buch erstellen"
#     }
#   }
# }

global_props

does nearly the same as to_svelte_props but adds the translations by the svelte view helper for all components.


Copyright © 2025-2027 sedlmair.ch. Distributed by MIT license.