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

[imp] Implement Backend Language Switcher #9126

Merged
merged 5 commits into from
Feb 18, 2016

Conversation

infograf768
Copy link
Member

This PR adds a new Toolbar Button to let admin switch the Backend Language to any language.
It replaces #9119 which was only letting switch to the Default Admin Language.

The purpose of the PR is to facilitate the work of devs, translators and admins in general.

After PR, one will get:
screen shot 2016-02-15 at 09 14 16

@richard67 @andrepereiradasilva @Kubik-Rubik
Thanks for testing.

* @return void
*/
public function switchAdminLanguage()
{
Copy link
Contributor

Choose a reason for hiding this comment

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

If you allow a param in this function ($languageId) then we can use it in a module lang switcher.
Also a check

if (isset($languageId))
{
  JFactory::getApplication()->setUserState('application.lang', $languageId);
}
else
{
$cid   = $this->input->get('cid', ''); 
...

}

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean we "could" use it, right?
Do you want to add one to core or would that just be to let a 3rd party create one?

Also, I would rather, if @joomla/cms-maintainers agree with your proposal, use $languageTag as it is not an id which is for $whatever in
`JFactory::getApplication()->setUserState('application.lang', $whatever)'

but the language tag, i.e fr-FR, en-GB, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup!
I find this an essential addition for backend users with multilingual sites. Right now I need to install 3PD extension for this really basic functionality.
Figuring out the variable type by reading the code is hard but yes $languageTag seems more appropriate! (I thought $cid was referring to a number)

@andrepereiradasilva
Copy link
Contributor

@infograf768 for usability how about reordering the buttons, first the ones related with options selected, them the general ones (not related to the options selected).

Also what to do you think of instead "Switch Backend Language" having "Switch to Language". Since the button only appear on the admin languages, IMHO probably makes more sense.

In other words:

instead of: Default | Install Languages | Switch Backend Language

this: Default | Switch to Language | Install Languages

@infograf768
Copy link
Member Author

@andrepereiradasilva
Ok for the order. Will wait all comments to update.
Asking @brianteeman for the string change.

@richard67
Copy link
Member

I have tested this item ✅ successfully on dbd6920

Tested with success. Works as discussed in #9119 at the end.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9126.

@MATsxm
Copy link

MATsxm commented Feb 15, 2016

I have tested this item ✅ successfully on dbd6920


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9126.

@MATsxm
Copy link

MATsxm commented Feb 15, 2016

At this point - works as described.

NOTE: the btn appears even if we have only one language istalled on backend
screen shot 2016-02-15 at 06 08 50


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9126.

@brianteeman
Copy link
Contributor

For consistency I think that this should be referred to as Administrator Language and not Backend Language


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9126.

@joomla-cms-bot
Copy link

This PR has received new commits.

CC: @MATsxm, @richard67


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9126.

@infograf768
Copy link
Member Author

I have modified the language strings as well as the order of the buttons.

This gives:
screen shot 2016-02-16 at 08 00 20

@MATsxm The button will behave the same way as the "Default" button which also displays when only one language is installed.

@andrepereiradasilva I guess that Switch Language does not need the "to".

Please test again

@dgt41
I prefer to let you make a specific PR for your request as I would not know where to stop the "else".

@richard67
Copy link
Member

I have tested this item ✅ successfully on 295bf8c


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9126.

@MATsxm
Copy link

MATsxm commented Feb 16, 2016

I have tested this item ✅ successfully on 295bf8c

#9126 works as expected - Thanks


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9126.

@infograf768
Copy link
Member Author

rtc. thanks for feedback and testing.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9126.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Feb 16, 2016
@joomla-cms-bot
Copy link

This PR has received new commits.

CC: @MATsxm, @richard67


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9126.

@infograf768
Copy link
Member Author

Folks, I will ask you to test again, sorry.
@brianteeman suggested that I change the success message to display the language Name and not the language Tag.
I think it is indeed much better.

One will now get:
screen shot 2016-02-17 at 12 24 55

@richard67 @MATsxm @andrepereiradasilva @brianteeman

@richard67
Copy link
Member

I have tested this item ✅ successfully on 49595b0

Just tested, works as before plus language full name instead of tag is used in the success message.

@infograf768 What last screenshot does not show (because I think you switched from English to English) is that the success message is in the language from before switching, as your first screenshot in the test description shows (switched from English to Italian: Title "Messagio" in Italian but message content in English. I guess we cannot change this in an easy way, otherwise you would have done it, right? Or is it by purpose?

I also assume that there is no other easy way to get the language full name so you have to parse the XML file, right?

Or could it maybe be obtained from the language lists's 1st column, e.g. with jQuery?

Anyway, for me it is good enough as it is now, and I hope it will go into 3.5.0 Beta 3 or RC.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9126.

@MATsxm
Copy link

MATsxm commented Feb 17, 2016

I have tested this item ✅ successfully on 49595b0

Thanks


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9126.

@infograf768
Copy link
Member Author

as your first screenshot in the test description shows (switched from English to Italian: Title "Messagio" in Italian but message content in English. I guess we cannot change this in an easy way, otherwise you would have done it, right?

Same issue when the user is set to Default Language and another language is set to default. The content of the message is picked from the former language. No idea how to solve this. If it is possible this should be another PR imho.

I did parse the xx-XX.xml file indeed. Easy enough. code is

        $file = JPATH_ADMINISTRATOR . '/language/' . $cid . '/' . $cid . '.xml';
        $info = JInstaller::parseXMLInstallFile($file);
        $languageName = $info['name'];

        if ($model->switchAdminLanguage($cid))
        {
            $msg = JText::sprintf('COM_LANGUAGES_MSG_SWITCH_ADMIN_LANGUAGE_SUCCESS', $languageName);
            $type = 'message';
        }
        else

@richard67
Copy link
Member

@infograf768 Thanks for the info, I just was curious. For me it is fine now as it is.

@andrepereiradasilva
Copy link
Contributor

i think you could also use JLanguage::parseXMLLanguageFile($path); don't really know the difference.

@brianteeman
Copy link
Contributor

@richard67 @infograf768 isnt the message always in english right now because it is a new language string that doesnt exist in the other languages so en-gb is always used as a fallback


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9126.

@brianteeman
Copy link
Contributor

I have tested this item ✅ successfully on 49595b0

Works perfectly for me - thanks @infograf768


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9126.

@richard67
Copy link
Member

@brianteeman Ahhhh, sure, you are right. Silly me!

@infograf768
Copy link
Member Author

@andrepereiradasilva

i think you could also use JLanguage::parseXMLLanguageFile($path); don't really know the difference.

It is deprecated.
https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/application/helper.php#L229-L231

@andrepereiradasilva
Copy link
Contributor

@gwsdesk
Copy link

gwsdesk commented Feb 17, 2016

Works as intended for me. Thanks JM

wilsonge added a commit that referenced this pull request Feb 18, 2016
[imp] Implement Backend Language Switcher
@wilsonge wilsonge merged commit 029b170 into joomla:staging Feb 18, 2016
@wilsonge wilsonge added this to the Joomla! 3.5.0 milestone Feb 18, 2016
@richard67
Copy link
Member

@infograf768 Thanks a lot for this great new feature. It helps a lot with testing (multi) language stuff in backend. I think it is worth to be mentioned in the new features of the release notes with an own head line.

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Feb 18, 2016
@infograf768 infograf768 deleted the admin_switcher branch February 18, 2016 10:40
@infograf768
Copy link
Member Author

BTW:

isnt the message always in english right now because it is a new language string that doesnt exist in the other languages so en-gb is always used as a fallback

Nope. As I stated above #9126 (comment) the message is in the former language. It is the same as Default change as you can test by setting an admin language to Default when logged with a user set to use Default language.

@infograf768
Copy link
Member Author

I have a solution for that. Will make a new PR for both Default and Switch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language Change This is for Translators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants