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

[ticket/13762] Moving language related functionality into a service #3535

Merged
merged 3 commits into from May 2, 2015

Conversation

CHItA
Copy link
Member

@CHItA CHItA commented Apr 14, 2015

@Nicofuma Nicofuma added this to the 3.2.0 milestone Apr 14, 2015
@Nicofuma
Copy link
Member

Replacing $user->lang[] with $user->lang() is definitively something to do one day but not today I think (to much trouble).

Anyway I'd like to keep the BC with the old $user->lang['key'] way. For that you can add a special treatment in the magic method __get()

@CHItA
Copy link
Member Author

CHItA commented Apr 14, 2015

Just reverted that commit while you were typing that message. BC definitely should be kept and my RegEx replace turned out pretty badly anyhow.

@@ -116,6 +116,12 @@ services:
- @controller.resolver
- @request_stack

language:
Copy link
Member Author

Choose a reason for hiding this comment

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

This service part should be rewritten, but I'm not sure how exactly.

Probably this part should be renamed to language.parent, made abstract, and then language service could link to it, and we could specify passing extension manager into the setter, but that should be environment dependent, so I'm not sure where it should be specified.

Copy link
Member

Choose a reason for hiding this comment

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

I think that we should split it into at least two services:

  • language_loader which will find the language files and load them when requested (basically it's a stateless service (minus caching) which as a load(<component>, <locale>) : array('key' => 'value') method or something similar).
  • language which will take a loader as parameter. This service will be used by everyone.

Copy link
Member

Choose a reason for hiding this comment

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

by the way, move this service definition to services_language.yml please

@Skouat
Copy link
Contributor

Skouat commented Apr 15, 2015

Hi,
The filename of phpBB/phpbb/language/loader/extenension_language_file_loader.php should be phpBB/phpbb/language/loader/extension_language_file_loader.php

public function get_available_languages()
{
// Find available language packages
$finder = new Finder();
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason why you don't use phpbb\finder ?

Copy link
Member Author

Choose a reason for hiding this comment

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

phpbb\finder seems to lack the functionality I use here, also caching is not an issue here.

Copy link
Member

Choose a reason for hiding this comment

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

and you want only the core language files, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mostly. This service used at two places, the installer, and the ACP language install module, it was implemented both places so this is the deduplication of it. And the assumption behind my code (and probably the old one as well) that a language is only installable when the core files are there, therefore I don't really care for extension language packs here.

Copy link
Member

Choose a reason for hiding this comment

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

fine with me

Copy link
Member

Choose a reason for hiding this comment

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

to be precise, each time we want to limit the depth we write the iterator chain manually

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this an issue then?

Copy link
Member

Choose a reason for hiding this comment

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

with our finder yes, but not with your PR :)

@Nicofuma
Copy link
Member

@Nicofuma
Copy link
Member

https://github.com/phpbb/phpbb/blob/3.1.x/tests/template/template_test_case.php#L124 you need to update the loader to set the variables (you can use the PHP reflection API for that)

@Nicofuma
Copy link
Member

same here: https://github.com/phpbb/phpbb/blob/3.1.x/tests/user/lang_test.php#L21 (and a few lines below)

@Nicofuma
Copy link
Member

please rebase

@Nicofuma
Copy link
Member

merged #3539 you can rebase

namespace phpbb\language\exception;

/**
* Exception thrown by \phpbb\language\language::get_plural_form()
Copy link
Member

Choose a reason for hiding this comment

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

explain what mean this exception and not which function throw it

*/
protected function load_common_language_files()
{
foreach ($this->common_language_files as $lang_file)
Copy link
Member

Choose a reason for hiding this comment

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

wrap it under if(!$this->common_language_files_loaded )

@CHItA CHItA force-pushed the ticket/13762 branch 5 times, most recently from 2d9c982 to 18be1d7 Compare April 24, 2015 15:27
@CHItA CHItA force-pushed the ticket/13762 branch 2 times, most recently from 0b493ee to 861311e Compare April 30, 2015 22:21
* @param $number int|float The number we want to get the plural case for. Float numbers are floored.
* @return int The plural-case we need to use for the number plural-rule combination
*
* @deprecated 3.2.0-dev (To be removed: 3.3.0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be "To be removed: 3.4.0"? (or 4.0.0)
Same for all other occurrences below.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not even sure if anyone uses this function (as it was called by user::lang()). So 3.3.0 is more then too much time to adopt.

@Nicofuma Nicofuma merged commit 9a99c9e into phpbb:master May 2, 2015
Nicofuma pushed a commit that referenced this pull request May 2, 2015
[ticket/13762] Moving language related functionality into a service
@CHItA CHItA deleted the ticket/13762 branch May 29, 2015 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants