dev-master
9999999-devMake custom specified data fields to share the same value across different locale/language versions.
MIT
The Requires
silverstripe field translatable untranslate
Make custom specified data fields to share the same value across different locale/language versions.
Jarkko Linnanvirta (Nickname: Taitava) posti (at) taitavasti.fi, (*1)
This module makes it possible to define fields that cannot be translated to different languages when using the Translatable module. For example, you may have a model called Person with two fields: name and description. You have installed the Translatable module in order to be able to provide the description field in different languages. But since a person's name is not (usually) translated, there is no reason to have to enter the person's name multiple times - once per every translation., (*2)
In practice, every time an object (that extends this module) gets saved to the database, its translations are iterated over and the values of fields marked as untranslatable are copied over to the other translations and saved., (*3)
The CMS module is not necessarily needed., (*4)
This is a very simple one to configure. But first, either download this module and unpack it to a folder named "untranslatablefields" under your site's root directory, or install via Composer:, (*5)
composer require "taitava/silverstripe-untranslatablefields:*"
Then create a new file: mysite/_config/untranslatablefields.yml and put the following content there:, (*6)
--- UntranslatableFields: fields: MyClass: - MyField - CommonField AnotherClass - AnotherField - CommonField
Also, remember to extend your classes with this module. Edit mysite/_config/config.yml and add the following lines:, (*7)
MyClass: extensions: - UntranslatableFieldsExtension AnotherClass: extensions: - UntranslatableFieldsExtension
These two configurations together render fields MyField and CommonField in MyClass and fields AnotherField and CommonField untranslatable. Note that specifying the classes does not affect any child classes!, (*8)
You can also do the opposite: Untranslate all but the specified fields! Just add invert: true
to
mysite/_config/untranslatablefields.yml:, (*9)
--- UntranslatableFields: fields: MyClass: - MyField - CommonField AnotherClass - AnotherField - CommonField invert: true
If the user saves and publishes for example a Page object, its different language versions will get saved, but not published by default. This is because the DataObject::write() method does not publish changes by default. UntranslatableFields can be set to do the publishing for DataObjects that has the Versioned extension., (*10)
This feature is off by default. To turn it on, add the following to mysite/_config/untranslatablefields.yml:, (*11)
UnstranslatableFields: auto_publish: true
Note: if the translation was in the Stage mode (= not published) before the write operation, it won't get published automatically even if this option is set to true. If there were an oldder published version, the changes are written to the newest (Staged) version and will not get published., (*12)
There are a couple of low level ways to give the CMS users a hint about untranslatable fields. This should also work in the general backend even without the CMS module and in the ModelAdmin of DataObjects., (*13)
You can add some custom CSS classes to the FormField elemnts of all untranslatable fields. Add this to mysite/_config/untranslatablefields.yml:, (*14)
UntranslatableFields: add_classes_to_cms: - untranslatable - 'another-class'
You can also set HTML attributes in the same way:, (*15)
UntranslatableFields: add_attributes_to_cms: - data-untranslatable: yes - title: "This field can't be translated separately. Changes to this field are saved across all existing translations."
Just for you to know: if you are untranslating fields that has no CMS fields, this feature won't interfere with them: the module only tries to add these classees/attributes to those fields that exist in the CMS/ModelAdmin editor., (*16)
Stuff that could be done:, (*17)
Make custom specified data fields to share the same value across different locale/language versions.
MIT
silverstripe field translatable untranslate