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

Problem with change language under Windows #165

Closed
DesRodman opened this issue Nov 20, 2020 · 3 comments
Closed

Problem with change language under Windows #165

DesRodman opened this issue Nov 20, 2020 · 3 comments

Comments

@DesRodman
Copy link

Hello team

I have problem with your extension in my yii2 project.

"yiisoft/yii2": "^2.0.39.2",
"codemix/yii2-localeurls": "^1.7.1"

At my laptop - which is working under Ubuntu 20.04 (checked in FireFox and Chrome) - extension works good (I can change languages)

But at same time at another laptop I have Windows 7 (checked in FireFox and Chrome) - and after selecting another language, extension back a language which is default in browser. So users have no chance to change language under Windows.
I also checked at Windows 10 and saw the same.

I tried to investigate this issue, and I have the same problem in some JavaScript code in my project
Was code (in was not workable under Windows also)

<script type="text/javascript">
    $('#delete-multiple').click(function() {
        $.post(
            "/black-list/delete-multiple",
            {
                pk : $('#phone-pjax').yiiGridView('getSelectedRows')
            },
            function (data) {
                alert(data);
                $.pjax.reload({container:'#phone-pjax'});
            }
        );
    });
</script>

Now I have the next code (and its workable)

<script type="text/javascript">
    $('#delete-multiple').click(function() {
        $.post(
            "<?php echo ((Yii::$app->language == Yii::$app->urlManager->defaultLanguage) ? '' : ('/'.Yii::$app->language)); ?>/black-list/delete-multiple",
            {
                pk : $('#phone-pjax').yiiGridView('getSelectedRows')
            },
            function (data) {
                alert(data);
                $.pjax.reload({container:'#phone-pjax'});
            }
        );
    });
</script>

I made change in URL, I added a language name... Maybe in your script need to make something like that?
Or how can I make it stable?

Thanks

@mikehaertl
Copy link
Collaborator

"/black-list/delete-multiple",

You should never ever hardcode any URLs to your app in your javascript code. Always use Url::to() to create the URL, than insert it at the apropriate place in your js code. This advice is independent of our library but true for any js code that uses URLs to your yii app. Otherwhise your code will break as soon as you add/modify some URL rules.

If you do this, your issue will be solved.

@DesRodman
Copy link
Author

I'm using exactly Url::to() for create a list of changing languages (https://prnt.sc/vmzr41)
Html::a(Html::img($lang->flag, ['alt' => $lang->name]).' '.$lang->name, Url::to(['/' . implode('/', $current_url), 'language' => $lang->url]), ['class' => 'dropdown-item']);

I used Url::to not correct?

@mikehaertl
Copy link
Collaborator

I don't know what you try to do here with Url::to(['/' . implode('/', $current_url) and I'm sorry, but I can not debug or develop your application for your.

I can't see a clear bug report here. If you think something is broken, please provide a simple(!!) example that is free of the surroundings of your application and demonstrates the problem so that we can reproduce it.

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

No branches or pull requests

2 participants