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

Feature/i18n permalinks #1092

Merged
merged 6 commits into from
Nov 4, 2021
Merged

Conversation

MamlukiSn
Copy link
Contributor

@MamlukiSn MamlukiSn commented Aug 20, 2021

Description

This PR enables the translation of permalinks.
Useful when frontend URL's are also translated based on the locale.

Usage

  1. Allows localization of the permalinkBase property of the ModuleController
//return an array from the getLocalizedPermalinkBase controller method with the keys being locales
//the slug attribute will be appended to the value

/**
* @return array
*/
protected function getLocalizedPermalinkBase()
{
    return [
        'en' => 'collection/artists',
        'fr' => 'collection/artistes',
    ];
}
  1. Allow localization of the customPermalink property by use of localizedCustomPermalink property instead
//pass localizedCustomPermalink to the form data which is an array with the keys being locales and values being the translated urls
protected function formData($request)
{
    return [
        'localizedCustomPermalink' => [
            'en' =>'https://website.com/en/news',
            'fr' =>'https://website.com/fr/nouvelles',
        ],
    ];
}

@daun
Copy link
Contributor

daun commented Aug 24, 2021

Nice to see somebody tackle this!

To follow the way other Twill features are handled, the localized permalinks should probably be supplied through a method on the controller, similar to the original getPermalinkBaseUrl method. E.g. getLocalizedPermalinkBaseUrls. Requiring the json_encode in every controller is error-prone and a separate method would make it easy to see what that code is doing. The array can be converted to json in blade.

@ifox ifox requested a review from pboivin October 29, 2021 23:28
Copy link
Contributor

@pboivin pboivin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @MamlukiSn, this is cool! I believe it's the final missing piece for fully configurable permalinks in TitleEditor.

I've added a few questions and comments below.

views/layouts/form.blade.php Outdated Show resolved Hide resolved
frontend/js/components/TitleEditor.vue Outdated Show resolved Hide resolved
Add localized permalinkbase trailing slashes in the frontend.

Provide fallback for undefined locales in getLocalizedPermalinkBase().
@pboivin pboivin merged commit 3da7ff0 into area17:2.x Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants