From 395b6fdb5df19eacc6a18e88cd81c023e89539b1 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Mon, 18 Sep 2023 10:19:37 +0100 Subject: [PATCH] Mention translation model in README --- README.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3e7ddac..8e89571 100644 --- a/README.md +++ b/README.md @@ -89,11 +89,26 @@ end You can now use `I18n.t('Your String')` to lookup translations in the database. -## Missing Translations +## Custom translation model + +By default, the gem relies on [the built-in translation model](https://github.com/svenfuchs/i18n-active_record/blob/master/lib/i18n/backend/active_record/translation.rb). +However, to extend the default functionality, the translation model can be customized: + +```ruby +class MyTranslation < I18n::Backend::ActiveRecord::Translation + def value=(val) + super("custom #{val}") + end +end -### Usage +I18n::Backend::ActiveRecord.configure do |config| + config.translation_model = MyTranslation +end +``` + +## Missing Translations -In order to make the `I18n::Backend::ActiveRecord::Missing` module working correctly pluralization rules should be configured properly. +To make the `I18n::Backend::ActiveRecord::Missing` module working correctly pluralization rules should be configured properly. The `i18n.plural.keys` translation key should be present in any of the backends. See https://github.com/svenfuchs/i18n-active_record/blob/master/lib/i18n/backend/active_record/missing.rb for more information.