laravel-streams / streams-core

Streams is an open-source web application engine for Laravel.
https://streams.dev
Other
169 stars 99 forks source link

Localization #724

Closed RyanThompson closed 2 years ago

RyanThompson commented 3 years ago

Currently, a generic "Transform" tool would be my best approach to abstracting a toolset that could accommodate multiple localization approaches. You can also use relations. The localization configuration should account for extensive configuration to account for any use case. Starting with basic relations for translations and {self}_{locale} stream "transforming" for stream sources and fields. Both approaches may be necessary for "localization" as a whole. In order to load another translation FROM an entry and to load FROM the translation source as opposed to the default stream for the translation if the app is in a non-default locale. The "translator" should be adaptable and follow an interface.

$entry->translate('en'); // Would utilize the relation or whatever you configure. Streams::entries('pages')->get(); // Get 'en' translations or whatever app locale is or inline ->translate('en') to cause that transforming to happen and change things for localization. Could be used for other fts.

RyanThompson commented 3 years ago

Column transformation could be like "{key}_{handle}" where "handle" would be the handle of the transformation (en, es, de, etc).

Stream transformation might turn "pages_pages" for example into "{table}_translation" an use a column restriction configuration - but basically create configurable/extensible transformation processors that we can use to accommodate localization.

These would need to perhaps use the workflow utility. Where each would be a standard process like changing the source or loading a relation and overriding the target values, whatever the translation actions are could be configured in key areas. Defaults built-in - ready to configure.

Pyro would use the stream transformation (translations table is a stream) - which would extend the base stream (pages_pages_translations stream extends pages_pages). So the entry would load it's extended version data as well.

We would also use the relation transformation for the loader using the entry - like $entry->transform('en') is the same as $entry->translate('en') but it would load another entry based on configured behavior.