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

I18n: get_locale calls involve much boilerplate code #2707

Open
zinigor opened this issue Sep 15, 2015 · 2 comments
Open

I18n: get_locale calls involve much boilerplate code #2707

zinigor opened this issue Sep 15, 2015 · 2 comments
Assignees
Labels
[Focus] i18n Internationalization / i18n, adaptation to different languages [Focus] Jetstream General [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it

Comments

@zinigor
Copy link
Member

zinigor commented Sep 15, 2015

When calling get_locale Jetpack code often checks for existence of the GL_Locales class and requires the file if it's not defined. This code is used in several places and can be abstracted to make everything more DRY:

if ( !class_exists( 'GP_Locales' ) ) {
    if ( !defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || !file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) {
        return false;
    }
    require JETPACK__GLOTPRESS_LOCALES_PATH;
}
@zinigor zinigor added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Focus] i18n Internationalization / i18n, adaptation to different languages labels Sep 15, 2015
@zinigor zinigor self-assigned this Sep 15, 2015
@zinigor zinigor added this to the 3.8 milestone Sep 15, 2015
@dereksmart dereksmart modified the milestones: Needs Triage, 3.8 Nov 3, 2015
@jeherve jeherve modified the milestones: 3.8.2, Needs Triage Nov 17, 2015
@kraftbj kraftbj modified the milestones: 3.8.2, 3.9 Dec 17, 2015
@jeherve jeherve modified the milestones: 4.0, 3.9 Jan 15, 2016
@jeherve jeherve modified the milestones: 4.1, 4.3 Jun 17, 2016
@richardmuscat richardmuscat modified the milestone: 4.3 Jul 7, 2016
@jeherve jeherve modified the milestone: 4.4 Jul 8, 2016
@samhotchkiss samhotchkiss modified the milestones: 4.4, Not Currently Planned Nov 9, 2016
@stale
Copy link

stale bot commented Jul 6, 2018

This issue has been marked as stale. This happened because:

  • It has been inactive in the past 6 months.
  • It hasn’t been labeled `[Pri] Blocker`, `[Pri] High`.

No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.

@stale stale bot added the [Status] Stale label Jul 6, 2018
@kraftbj kraftbj removed this from the Not Currently Planned milestone Jan 26, 2021
@stale stale bot removed the [Status] Stale label Jan 26, 2021
@jeherve jeherve added the General label Apr 4, 2024
@jeherve
Copy link
Member

jeherve commented Apr 4, 2024

I think that is still very much an issue:

  • JETPACK__GLOTPRESS_LOCALES_PATH now refers to jetpack_vendor/automattic/jetpack-compat/lib/locales.php.
  • This file is the only file left in the Compat package, and the only reason for that package to stick around.
  • We have references to JETPACK__GLOTPRESS_LOCALES_PATH and attempts to fetch a site locale that is compatible with WordPress.com all over the codebase.
  • The mu-wpcom package includes its own way of getting a WordPress.com-compatible locale:
    /**
    * Returns ISO 639 conforming locale string.
    *
    * @param string $language a language tag to be converted e.g. "en_US".
    * @return string ISO 639 locale string e.g. "en"
    */
    function get_iso_639_locale( $language ) {
  • Folks are interested in getting something like that in JS as well ; see Blogging Prompt: preserve language on answers link #36730.

@zinigor @ice9js Do you think this could be a mini project for Garage? Maybe we could retire the Compat package, and have a proper common class and methods one can use to fetch a site locale, with an option to get a WordPress.com-compatible locale, and use that everywhere.
If we had that, we could pass that locale from PHP to JS here instead of creating a new JS utility.
We could also take that opportunity to update our copy of GP_Locales to include the changes that were added to GlotPress in the past 2 years.

The class and methods should be in a package that's available to the Jetpack plugin, to the mu-wpcom plugin, and others. I don't know if that's worth creating a new package though?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] i18n Internationalization / i18n, adaptation to different languages [Focus] Jetstream General [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

No branches or pull requests

6 participants