-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.php
79 lines (65 loc) · 2.07 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Vannut\TransEXT;
class Plugin extends \System\Classes\PluginBase
{
public function boot()
{
$this->app['Illuminate\Contracts\Http\Kernel']
->pushMiddleware('Vannut\TransEXT\Middleware\RewriteLocaleForIndexPage');
}
/**
* @var array Plugin dependencies
*/
// public $require = ['Rainlab.Translate'];
public function pluginDetails()
{
return [
'name' => 'Translate Extension',
'description' => 'Adds some logic to translate plugin',
'author' => 'Richard @ Van Nut',
'icon' => 'icon-plus'
];
}
public function registerComponents()
{
return [
'Vannut\TransEXT\Components\HeadAlternateHrefLangElements' => 'alternateHrefLangElements',
'Vannut\TransEXT\Components\LocaleSwitcher' => 'localeSwitcher'
];
}
public function registerMarkupTags()
{
return [
'filters' => [
],
'functions' => [
'asses_menu_item_url' => [$this, 'twigAssesMenuItemUrl'],
]
];
}
/**
* Assesses the url, and adds the locale for non-default locales, while
* it strips the locale for the default locale.
* @param String $url
* @param String $locale the current locale
* @param String $defaultLocale default locale of the october installation
* @return String the correct relative url
*/
public function twigAssesMenuItemUrl($url, $locale, $defaultLocale)
{
$locale = strtolower($locale);
$defaultLocale = strtolower($defaultLocale);
if ($locale !== $defaultLocale) {
// is het switch_locale?
if (strpos($url, '/switch_locale/') === false) {
// niet gevonden...
// dus aanpassen
$path = parse_url($url, PHP_URL_PATH);
return '/'
.$locale
.str_replace('/'.$locale.'/', '/', $path);
}
}
return $url;
}
}