Comments (8)
I don't use that user module. Does it work without it? Do you have to add any URL configuration for that module?
from yii2-localeurls.
As I understand, the problem arises precisely when called from any module. Looks like as Yii2 bug.
In addition, there is a problem when using links with data-method=POST. After redirect the request is converted to GET. I think this is also a Yii bug.
But if you will have a decision it will be very good.
The bug is in this application
from yii2-localeurls.
Hmm. I've used it from modules and had no problems so far. But I can check again.
About the data-method POST links: They should already point to the correct language URL. Because when you load the page, which contains such a link, you should already be redirected to your language. So this should never be a problem.
from yii2-localeurls.
I think, that dektrium/yii2-user have bad realisation. Me need this solution and I will see what not work there. Maybe fix it.
from yii2-localeurls.
Generate promlem this:
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseUrl.php#L132-L138
It is occurs bacause this
https://github.com/codemix/yii2-localeurls#example-language-selection-widget
$route = Yii::$app->controller->route; // <---- THIS
$appLanguage = Yii::$app->language;
$params = $_GET;
//......
In $route we get wrong route if the module is activated. (e.g. dektrium/yii2-user).
As second version it is Yii bug somewhere in that place where I have pointed above.
Yii::$app->controller->route // MAY BE THIS IS BUG!
Or this on generate
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseUrl.php#L132-L138
FOR FIX. Need use additional normalize in language switcher. It's bad hack but it's working.
$route = Yii::$app->controller->route;
$moduleId = Yii::$app->controller->module->getUniqueId();
$params = $_GET;
if($moduleId) {
$route = strpos($route, $moduleId) == 0 ? substr($route, strlen($moduleId) + 1) : $route;
}
array_unshift($params, $route);
$localeUrlsLanguages = Yii::$app->localeUrls->languages;
foreach ($localeUrlsLanguages as $language) {
$params['language'] = $language;
$label = self::label($language);
if ($label === null) {
throw new yii\base\InvalidConfigException('Language translate not support');
} else {
$this->items[] = [
'label' => $label,
'url' => $params,
];
}
}
parent::init();
Late with my the project, so who can write this bug in the Community framework. Good by!
from yii2-localeurls.
I think, all you have to change is to add a /
in front of the route:
<?php
$route = '/'.Yii::$app->controller->route;
I've tested it here and it works, but there may be situations where it's still making problems, not sure.
@wartur Can you confirm, that this fix works for you?
from yii2-localeurls.
@mikehaertl yea! it's work! Thanks. It's good implementation.
Now I publick own Langage Switcher. I get image from Joomla Langage switcher. If you want, you can set your own images.
<?php
namespace app\widget\special;
use Yii;
use yii\helpers\Html;
/**
* Переключатель языков.
* Выводит флаги языков по тому же принципу как это сделано в Joomla
*/
class LanguageSwitcher extends \yii\widgets\Menu
{
/**
* Специальная конфигурация меню
*/
public function init()
{
// отключим энкодер лейблов
$this->encodeLabels = false;
// конфигугируем меню
$route = '/' . Yii::$app->controller->route;
$appLanguage = Yii::$app->language;
$params = $_GET;
array_unshift($params, $route);
$localeUrlsLanguages = Yii::$app->localeUrls->languages;
foreach ($localeUrlsLanguages as $language) {
$params['language'] = $language;
$this->items[] = [
'label' => self::imageLabel($language),
'url' => $params,
'active' => $language == $appLanguage
];
}
parent::init();
}
/**
* Генерация изображений меню
* В качестве изображений берутся изображения Joomla
* @staticvar array $labels список изображений
* @param string $code код языка
* @return string HTML строка с генерацией изображений для языка
* @throws yii\base\InvalidConfigException исключение происходит, если нет конфигурации для данного языка
*/
public static function imageLabel($code)
{
static $labels = [];
if (empty($labels)) {
$labels = [
'en-US' => Html::img('/info/media/mod_languages/images/en.gif', [
'alt' => self::label('en-US'),
'title' => self::label('en-US'),
]),
'ru' => Html::img('/info/media/mod_languages/images/ru.gif', [
'alt' => self::label('ru'),
'title' => self::label('ru'),
]),
'de' => Html::img('/info/media/mod_languages/images/de.gif', [
'alt' => self::label('de'),
'title' => self::label('de'),
]),
'it' => Html::img('/info/media/mod_languages/images/it.gif', [
'alt' => self::label('it'),
'title' => self::label('it'),
]),
'es' => Html::img('/info/media/mod_languages/images/es.gif', [
'alt' => self::label('es'),
'title' => self::label('es'),
]),
];
}
if (empty($labels[$code])) {
throw new yii\base\InvalidConfigException('Language translate not support');
}
return $labels[$code];
}
/**
* Генерация названий языков на разных языках
* @staticvar array $labels список изображений
* @param string $code код языка
* @return string строка с названием языка с переводом на текущем языке
* @throws yii\base\InvalidConfigException исключение происходит, если нет конфигурации для данного языка
*/
public static function label($code)
{
static $labels = [];
if (empty($labels)) {
$labels = [
'en-US' => Yii::t('app/language_switcher', 'English'),
'ru' => Yii::t('app/language_switcher', 'Russian'),
'de' => Yii::t('app/language_switcher', 'German'),
'it' => Yii::t('app/language_switcher', 'Italian'),
'es' => Yii::t('app/language_switcher', 'Spanish'),
];
}
if (empty($labels[$code])) {
throw new yii\base\InvalidConfigException('Language translate not support');
}
return $labels[$code];
}
}
It's my draft style
.language-switcher {
}
.language-switcher .container{
text-align: right;
position: relative;
margin-top: -20px;
z-index: 2;
}
.language-switcher ul{
margin: 0;
padding: 0;
list-style: none;
}
.language-switcher li{
display: inline-block;
margin-left: 5px;
margin-right: 5px;
width: 25px;
text-align: center;
}
.language-switcher li.active {
/*border-bottom: red medium solid;*/
background-color: #222;
border: #080808 1px solid;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius-bottomright: 5px;
-moz-border-radius-bottomleft: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
}
Thanks all. Good by.
from yii2-localeurls.
Ok, thanks for sharing.
from yii2-localeurls.
Related Issues (20)
- Problem with default language HOT 3
- Redirect from https to http HOT 1
- Ajax also redirects when enableLanguagePersistence is turned on HOT 2
- Regular expression trouble HOT 5
- Using GeoIp as primary language detection method HOT 2
- Support for different domains HOT 2
- The page keeps redirecting HOT 1
- index.php is shown in browser url HOT 1
- How can i change language position in url HOT 2
- Please fix this define HOT 3
- Url::to with rules HOT 1
- One language for all EU locales HOT 1
- Problem with change language under Windows HOT 3
- Some issues with yii2-localeurls
- using Yii functionality HOT 2
- Bug in tests HOT 1
- The configuration for the "localeUrls" component must contain a "class" element. HOT 1
- Generating URL with custom urlRule HOT 2
- Help me please. Error with route. HOT 3
- Redirect for specific languages HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-localeurls.