Problem/Motivation

Locale module still has a bunch of legacy include files. As part of the core-wide initiative #3097045: [META] Provide modern replacements for and deprecate the legacy include files this issue focuses on Locale module.

Include files

  • locale.batch.inc #3581303: Convert locale batch callbacks
    • locale_translation_batch_version_check
    • locale_translation_batch_status_check
    • locale_translation_batch_status_finished
    • locale_translation_batch_fetch_download
    • locale_translation_batch_fetch_import
    • locale_translation_batch_fetch_finished
  • File management #3577671: Modernize locale file handling
    • locale_translation_http_check
    • locale_translation_download_source
  • locale.bulk.inc
    • batch related #3581303: Convert locale batch callbacks
      • locale_translate_batch_import_files
      • locale_translate_batch_build
      • locale_translate_batch_import
      • locale_translate_batch_import_save
      • locale_translate_batch_refresh
      • locale_translate_batch_finished
      • locale_config_batch_update_components
      • locale_config_batch_build
      • locale_config_batch_update_default_config_langcodes
      • locale_config_batch_set_config_langcodes deprecated
      • locale_config_batch_update_config_translations
      • locale_config_batch_refresh_name deprecated
      • locale_config_batch_finished
    • File management #3577671: Modernize locale file handling
      • locale_translate_get_interface_translation_files
      • locale_translate_file_create
      • locale_translate_file_attach_properties
      • locale_translate_delete_translation_files
  • locale.compare.inc
    • #3037031: Convert locale.compare.inc to a service (note 1)
      • locale_translation_flush_projects
      • locale_translation_build_projects
      • locale_translation_project_list
      • _locale_translation_prepare_project_list
      • locale_translation_default_translation_server
      • locale_translation_check_projects
      • locale_translation_check_projects_batch
      • locale_translation_batch_status_build
      • _locale_translation_batch_status_operations
      • locale_translation_check_projects_local
  • locale.fetch.inc #3572339: Modernize locale.fetch.inc
    • Already deprecated
  • locale.pages.inc
    • Already deprecated
  • locale.translation.inc

Module file

Constants

There are several manual require_once and loadInclude.
locale.translation.inc is manually required by:

  • locale.batch.inc
  • locale.compare.inc
  • locale.fetch.inc

Using moduleHandler there are many cross includes.

  • batch
    • includes bulk
  • bulk
    • compare
  • fetch
    • compare
  • module
    • bulk
    • compare
    • fetch
    • translation
  • translation
    • compare
    • fetch

Locale related, but not in scope

Note 1: Part of #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset()
Note 2: Part of #2999721: [META] Deprecate the legacy include files before Drupal 9
Note 3: Part of #1861442: [meta] Review of Drupal\Component\GetText files

Steps to reproduce

Take one file at a time deprecate and move all functions to .module
Deprecate file

Work on constants separately
Start with translations.inc since it is manually required three times.
This will break the chain fastest.

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

Sutharsan created an issue. See original summary.

sutharsan’s picture

Issue summary: View changes
sutharsan’s picture

Issue summary: View changes
andypost’s picture

gábor hojtsy’s picture

Fantastic collection. Locale has a lot of history ;) I think chipping away at this in manageable pieces is the best strategy. Hopefully we have enough existing test coverage to ensure refactored things still work. Also we need to identify in each case which parts are "API" and therefore need a full-on @deprecated/@trigger_error treatment. Hopefully most are not.

gábor hojtsy’s picture

Issue summary: View changes

Reparenting constants to this one, since its parent has been fixed for a while.

sutharsan’s picture

I'm working on a spreadsheet to identify procedural functions of Locale module that could be considered candidates for conversion. But Google has changed its interface and I can't find a way to share the content publicly. Slack or mail me your email and I will grand you access.

gábor hojtsy’s picture

#2927222: Move cache invalidation to event out of TranslateEditForm::submitForm() has been clarified. I removed this issue as it's parent, but maybe it is still related. No clear cut lines here :D

sutharsan’s picture

This spreadsheet list all procedural functions of Locale module (not hooks, not preprocess) which may be involved in modernizing. I'm looking at functions that naturally belong together or share enough ground to be grouped together.

https://docs.google.com/spreadsheets/d/1rK4HuF_8fLuHdkspOKXBoJNt7eo-V6NN...

DM me for access.

sutharsan’s picture

Issue summary: View changes
andypost’s picture

Version: 9.3.x-dev » 9.4.x-dev

Moving to 9.4/10

Used to check old issues and found great schema #1189184-200: OOP & PSR-0-ify gettext .po file parsing and generation

GettextOOP.png

Author is Gábor Hojtsy)

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
claudiu.cristea’s picture

Issue summary: View changes
Related issues: +#2660338: Deprecate locale_get_plural
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
andypost’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

dcam’s picture

While reviewing #3586472: locale_string_is_safe fails on valid safe html I noted that Drupal\Tests\locale\Kernel\LocaleStringIsSafeTest::testLocaleStringIsSafe() can be converted to a Unit test when locale_string_is_safe() is moved from the .module file into a class. I assume it isn't already a Unit test because of the global procedural function calls.

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

I just checked how many search results there are for each function. I think some of the hook related ones should be grouped:

locale_translatable_language_list 14 results
locale_get_plural 8 results
locale_system_set_config_langcodes 2 results, only tests already replaced

locale_system_update 3 results can move to LocaleHooks protected maybe
locale_system_remove 2 results can move to LocaleHooks protected maybe
locale_js_translate 1 results can move to LocaleHooks protected maybe
locale_form_language_admin_add_form_alter_submit 2 results can move to LocaleHooks
locale_form_language_admin_edit_form_alter_submit 1 result can move to LocaleHooks
locale_system_file_system_settings_submit 0 results already deprecated
locale_translation_status_delete_languages 1 result can move to LocaleHooks

locale_is_translatable 8 results
locale_translation_get_file_history 12 results
locale_translation_update_file_history 3 results
locale_translation_file_history_delete 2 results
locale_translation_get_status 26 results
locale_translation_status_save 5 results
locale_translation_status_delete_projects 2 results only deletes keyvalue
locale_translation_clear_status 3 results only deletes keyvalue and state
locale_translation_use_remote_source 6 results only checks config
locale_string_is_safe 11 results
_locale_refresh_translations 3 results
_locale_refresh_configuration 1 result inline in TranslateEditForm
_locale_strip_quotes 5 results
_locale_parse_js_file 6 results
_locale_invalidate_js 5 results
_locale_rebuild_js 4 results
locale_translation_language_table 1 result inline in TranslationStatusForm

berdir’s picture

Replying here, re #2660338: Deprecate locale_get_plural and #42:

I think it might be better to focus on locale_get_plural() there. That's a non-trivial case that goes outside of locale module. not sure if that needs to remain postponed, I don't think it directly conflicts with the others too much, but it's been helpful to focus on those issues one-by-one.

Agreed on grouping a bunch of functions that we move to protected methods on the hook service, the system ones and possibly also JS. Plus, several underscored helpers are called through locale_js_translate() that could go in there as well.

Maybe one other issue for everything form related. note: locale_translation_language_table is a callback, agree it can be a static method on the form, not "inline" though. _locale_refresh_configuration() unsure, while that one is only called from the form, it's right next do _locale_refresh_translations(), which has 2 additional calls, might make sense to keep them together.

The leftovers are then I think one or multiple utility service(s), we can split depending on their dependencies for example. locale_translatable_language_list() and locale_is_translatable() are clearly related, locale_translation_use_remote_source() kind of. locale_string_is_safe() and then there's not too much left.

nicxvan’s picture

Yes after doing the review of usages I think you're right I'll update the plural issue in a bit.

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes