$translatable wild card fields

Hello,

We want to translate our website. However we have more than 500 unique fields. Adding this to the translatable variable will be time consuming and prone to errors. Is there a way to translate the whole fileds.yaml file? Or to use a wild card kind of.

For example:

$translatable = [β€œ*”];

This should translate every field in that particular model.

I am thinking to add the $translatable in onRun. Loop through fields.yaml file and add every field to $translatable array.

Thanks.

@daft @artistro08 any insight on this?

First of all, I advise you to make sure that all the fields really need to be translatable and all of those fields can be translated with Rainlab.Translate. This will be very ressource intensive, depending on how many fields per model you have.

I would go the other way and export all columns with type TEXT or VARCHAR form the DB table schema. This way you should have a relatively small set of attributes to check and insert into the translatable array. And this should be done either in a seeder, a migration or as a separate script, as this should ideally only run or be done once - certainly not in any onRun method (which sound a methods from a component - not the best place imho).

Time consuming and prone to errors might be the case, but an uncontrolled blanket translatable will certainly be worse.

2 Likes

This was going to be my exact reply more or less. It’s going to take a minute to get everything translated, but having a structure and setting it up for translation is probably the best bet.

Tailor might be too resource intensive to translate all the fields at once, but I know that rainlab.translate has this built-in.

If you have all of the translations and you’re sure that the fields won’t change, I will go the rainlab.translate route

1 Like

Thanks @artistro08 and @marco.grueter.