Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I hope to customize the locale and item_id fields #207

Open
hteen opened this issue Nov 11, 2024 · 2 comments
Open

I hope to customize the locale and item_id fields #207

hteen opened this issue Nov 11, 2024 · 2 comments
Labels
common Issue related to the "laravel-lang/common" package feature New feature or request

Comments

@hteen
Copy link

hteen commented Nov 11, 2024

Feature description

When using $video->getTranslation("title") to get the title, the final SQL generated is:

select * from `video_translations` where `locale` in (zh_CN, en) and `video_translations`.`item_id` in (1)

Reading the source code, I found that locale and item_id cannot be customized

@hteen hteen added common Issue related to the "laravel-lang/common" package feature New feature or request labels Nov 11, 2024
@andrey-helldar
Copy link
Member

andrey-helldar commented Nov 11, 2024

The item_id really can't be customizable, as it's not necessary. This field is rigidly bound to a specific record of the main table and has a mapping to the locale field, which together are included in a composite unique index.

The locale field also cannot be customized because it belongs to a specific localization.

The query includes the condition where locale in (zh_CN, en) because your application is requesting a Chinese localization and, in case a translation is not available, it will get an English translation. The models.filter.enabled parameter of the config/localization.php config file is responsible for this filtering. If you turn it off, the query will return all created localizations.

Also, if you need to get a translation for a localization other than main or fallback, pass the localization as the second argument to the getTranslation method in one of the ways. For example:

use LaravelLang\LocaleList\Locale;

$video->getTranslation('title', 'fr');
$video->getTranslation('title', Locale::French);

Otherwise, the translation for the currently active localization will be returned by default, and if this translation is not in the database, then the fallback will be returned.

@andrey-helldar
Copy link
Member

And why do you want to customize the values of these fields?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Issue related to the "laravel-lang/common" package feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants