Problem/Motivation

locale.compare.inc has a bunch of intertwined logic for tracking translations and batches.
Let's start organizing the non batch related code here.

Proposed resolution

  • Move the logic from locale.compare.inc into a new service LocaleProjectRepository.
  • Move the two project check methods to LocaleProjectChecker
  • Create new LocaleTranslatableProject value object
  • Deprecate all functions unrelated to batch from locale.compare.inc.
  • Deprecate LocaleProjectStorageInterface and services and move relevant methods to the new LocaleProjectRepository service

Remaining tasks

Update the CRs if necessary after merging this:

Follow up:
#3589049: Explore avoiding buildProjects in the TranslationStatusForm
#1842380: Convert $source object to a LocaleTranslationSource class
#3589344: Remove the ability to have enabled/disabled projects in the locale project repository

User interface changes

N/A

API changes

  • New service LocaleProjectRepository
  • New service LocaleProjectChecker
  • Deprecated functions:
    • 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_local()

  • Deprecated services and classes:
    • locale.project
    • LocaleProjectStorageInterface
    • LocaleProjectStorage

    The relevant methods from the deprecated service have been moved to LocaleProjectRepository, see the CR for full details.
    There is a new LocaleTranslateableProject value object.

    Data model changes

    N/A

    Release notes snippet

    N/A

  • Issue fork drupal-3037031

    Command icon Show commands

    Start within a Git clone of the project using the version control instructions.

    Or, if you do not have SSH keys set up on git.drupalcode.org:

    Comments

    claudiu.cristea created an issue. See original summary.

    claudiu.cristea’s picture

    Issue summary: View changes
    claudiu.cristea’s picture

    claudiu.cristea’s picture

    claudiu.cristea’s picture

    Status: Active » Needs review
    StatusFileSize
    new40.96 KB

    OMG, locale is Hell!

    This is just a working patch. Far away to be finished.

    Status: Needs review » Needs work

    The last submitted patch, 5: 3037031-5.patch, failed testing. View results
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

    claudiu.cristea’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new6.04 KB
    new41.13 KB

    Narrowing failures.

    Status: Needs review » Needs work

    The last submitted patch, 7: 3037031-7.patch, failed testing. View results
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

    claudiu.cristea’s picture

    [removed]

    claudiu.cristea’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new50.27 KB
    new15.09 KB

    Fixed failures, coding standards. Added deprecation test.

    Version: 8.7.x-dev » 8.8.x-dev

    Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

    claudiu.cristea’s picture

    Issue summary: View changes
    StatusFileSize
    new51.69 KB
    new25.24 KB
    • Moved the deprecation messages to 8.8.x.
    • Deprecate the usage of drupal_static_reset('locale_translation_project_list'). Add test.
    • Add a cache reset method to the new service.
    • Fixed IS.
    • Fixed CR.

    Version: 8.8.x-dev » 8.9.x-dev

    Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

    Version: 8.9.x-dev » 9.1.x-dev

    Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

    kishor_kolekar’s picture

    StatusFileSize
    new49.18 KB

    #12 Patch Re-rolled for 9.1.x
    Please review

    daffie’s picture

    Status: Needs review » Needs work

    @kishor_kolekar: The testbot is not happy with your reroll. At least the deprecation messages need to be updated to deprecate in 9.1 and removed in 10.0.

    hardik_patel_12’s picture

    Status: Needs work » Needs review
    Issue tags: +Bug Smash Initiative
    StatusFileSize
    new49.2 KB

    Updating deprecate message and re-rolled the patch.

    quietone’s picture

    Issue tags: -Bug Smash Initiative

    @Hardik_Patel_12, Thanks for working on this issue. The types of issues being worked on by the Bug Smash Initiative are listed on the Bug Smash Initiative page and does not include Tasks. So, I am removing the tag.

    hardik_patel_12’s picture

    @quietone , sure will keep in mind this. Thanks for your suggestion.

    kishor_kolekar’s picture

    Thank you @daffie for ur suggestion.
    Thanks @Hardik_Patel_12 for working on it.

    daffie’s picture

    Status: Needs review » Needs work

    Testbot still not happy.

    hardik_patel_12’s picture

    StatusFileSize
    new48.95 KB

    Solving failed test cases. Kindly follow a new patch.

    hardik_patel_12’s picture

    Status: Needs work » Needs review

    Status: Needs review » Needs work

    The last submitted patch, 22: 3037031-22.patch, failed testing. View results
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

    msuthars’s picture

    Assigned: Unassigned » msuthars
    msuthars’s picture

    StatusFileSize
    new52.67 KB
    new13.14 KB

    Fixed the coding standard and testcase issues.

    msuthars’s picture

    Assigned: msuthars » Unassigned
    Status: Needs work » Needs review
    msuthars’s picture

    StatusFileSize
    new52.7 KB
    new12.74 KB

    Updated patch.

    Version: 9.1.x-dev » 9.2.x-dev

    Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

    Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

    sutharsan’s picture

    StatusFileSize
    new52.75 KB

    Patch re-rolled

    claudiu.cristea’s picture

    Status: Needs review » Needs work
    1. +++ b/core/includes/bootstrap.inc
      @@ -625,6 +625,12 @@ function &drupal_static($name, $default_value = NULL, $reset = FALSE) {
      +      @trigger_error("Using drupal_static_reset() with 'locale_translation_project_list' as argument is deprecated in Drupal 9.1.0 and will be removed in Drupal 10.0.0. See https://www.drupal.org/node/3037033.", E_USER_DEPRECATED);
      
      +++ b/core/modules/locale/locale.compare.inc
      @@ -3,8 +3,17 @@
      + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. See each
      ...
      +@trigger_error(__FILE__ . ' is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. See individual methods in the file for individual deprecation notices with upgrade instructions. See https://www.drupal.org/node/3037033.', E_USER_DEPRECATED);
      
      @@ -16,8 +25,14 @@
      + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
      ...
      +  @trigger_error('locale_translation_flush_projects() is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. Use \Drupal\locale\LocaleProjectStorageInterface::deleteAll(). See https://www.drupal.org/node/3037033.', E_USER_DEPRECATED);
      
      @@ -41,51 +56,15 @@ function locale_translation_flush_projects() {
      + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
      ...
      +  @trigger_error('locale_translation_build_projects() is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. Use \Drupal\locale\LocaleProjectStatusInterface::buildProjects(). See https://www.drupal.org/node/3037033.', E_USER_DEPRECATED);
      
      @@ -93,9 +72,15 @@ function locale_translation_build_projects() {
      + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. There's
      
      @@ -135,8 +120,14 @@ function locale_translation_project_list() {
      + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. There's
      ...
      +  @trigger_error("_locale_translation_prepare_project_list() is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. There's no replacement for this function. See https://www.drupal.org/node/3037033.", E_USER_DEPRECATED);
      
      @@ -155,8 +146,14 @@ function _locale_translation_prepare_project_list($data, $type) {
      + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. There's
      ...
      +  @trigger_error("locale_translation_default_translation_server() is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. There's no replacement for this function. See https://www.drupal.org/node/3037033.", E_USER_DEPRECATED);
      
      @@ -176,22 +173,14 @@ function locale_translation_default_translation_server() {
      + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
      ...
      +  @trigger_error("locale_translation_check_projects() is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. Use \Drupal\locale\LocaleProjectStatusInterface::checkProjects() instead. See https://www.drupal.org/node/3037033.", E_USER_DEPRECATED);
      
      @@ -206,8 +195,14 @@ function locale_translation_check_projects($projects = [], $langcodes = []) {
      + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. There's
      ...
      +  @trigger_error("locale_translation_check_projects_batch() is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. There's no replacement for this function. See https://www.drupal.org/node/3037033.", E_USER_DEPRECATED);
      
      @@ -230,8 +225,14 @@ function locale_translation_check_projects_batch($projects = [], $langcodes = []
      + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. There's
      ...
      +  @trigger_error("locale_translation_batch_status_build() is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. There's no replacement for this function. See https://www.drupal.org/node/3037033.", E_USER_DEPRECATED);
      
      @@ -262,18 +263,16 @@ function locale_translation_batch_status_build($projects = [], $langcodes = [])
      + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
      ...
      +  @trigger_error("_locale_translation_batch_status_operations() is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. Use \Drupal\locale\LocaleProjectStatusInterface::remoteTranslationStatusOperations() instead. See https://www.drupal.org/node/3037033.", E_USER_DEPRECATED);
      
      @@ -294,19 +293,13 @@ function _locale_translation_batch_status_operations($projects, $langcodes, $opt
      + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
      ...
      +  @trigger_error("locale_translation_check_projects_local() is deprecated in Drupal 9.1.0 and will be removed before Drupal 10.0.0. Use \Drupal\locale\LocaleProjectStatusInterface::checkProjectsLocal() instead. See https://www.drupal.org/node/3037033.", E_USER_DEPRECATED);
      

      The Drupal version should be updated here and also in change record. Also the message pattern should follow https://www.drupal.org/project/coding_standards/issues/3024461.

    2. +++ b/core/modules/locale/src/LocaleProjectStatusInterface.php
      @@ -0,0 +1,78 @@
      +   * Resets the project list internal cache
      

      Needs a dot at the end.

    sutharsan’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new22.62 KB
    new52.64 KB

    Both above comments are addressed.

    Also added missing 'array' type hints in LocaleProjectStatusInterface::remoteTranslationStatusOperations and LocaleProjectStatus:

    -  public function remoteTranslationStatusOperations($projects, $langcodes, $options = []) {
    +  public function remoteTranslationStatusOperations(array $projects, array $langcodes, array $options = []) {
    
    sutharsan’s picture

    StatusFileSize
    new1.66 KB
    new52.64 KB

    Spell check fixes.

    Status: Needs review » Needs work

    The last submitted patch, 34: 3037031-34.patch, failed testing. View results

    sutharsan’s picture

    Status: Needs work » Needs review
    StatusFileSize
    new8.76 KB
    new52.46 KB

    Trying to fix the deprecation tests.

    I could not find a way to cover the deprecation error triggered at the top of the .inc file. I decided to remove this trigger althogether. Not a nice approach, but the best I could come up with.

    andypost’s picture

    Issue tags: +Kill includes
    Related issues: +#3036982: [pp-1] Deprecate locale_translation_get_projects() and locale_translation_clear_cache_projects()

    Quickly skimed a pacth and last interdiff, will do deeper review later tonight

    +++ b/core/modules/locale/locale.compare.inc
    @@ -11,9 +11,6 @@
    -@trigger_error(__FILE__ . ' is deprecated in Drupal 9.3.0 and is removed from Drupal:10.0.0. See individual methods in the file for individual deprecation notices with upgrade instructions. See https://www.drupal.org/node/3037033.', E_USER_DEPRECATED);
    

    not sure this line need to be removed, as this file no longer loaded... contrib or custom code using to load it should fail

    sutharsan’s picture

    Re #37, I removed this line because I could not find a way to get the test working _with_ this line. As I tried to explain in #36.
    Further I searched for other other .inc files which got deprecated to look for a pattern. #2044435: Convert pager.inc to a service deprecate pager.inc, it did not use a deprecation message at file level. I found no deprecated .inc files in core. Further the existing documentation standard on @deprectated only mentions function, method, class. The coding standards issue mentioned in #32 extends this list further (below), but does not mention deprecation of files. Therefore I propose to remove the @deprectated at file level and only use it for functions.

    %thing%
        What is being deprecated - for example, the class name, method name, function name, service name or the use or optional status of a parameter
    sutharsan’s picture

    This issue converts _all_ functions in locale.compare.inc into one service where each function gets a method. In the current code of Locale module I found the LocaleConfigManager service which (a.o.) is called by batch functions in locale.bulk.inc.

    This made me wonder whether it is proper architecture to include these batch functions into a service like LocaleConfigManager and LocaleProjectStatus (this issue). I am leaning towards separating the batch function from the functions that do the "work". In other words to move the batch building and batch operation/finish functions out of this patch.

    berdir’s picture

    AFAIK, batch callbacks can't be on services yet, only functions or static methods. Closest I managed is a batch function "dispatcher" than then calls the service. See _simplenews_batch_dispatcher() in simplenews.module.

    sutharsan’s picture

    @Berdir, Thanks for the tip, _simplenews_batch_dispatcher() is a clever way to call a service method from where only call_user_function_array is used by Drupal's batch API.

    Let me break down the batch related parts of batch code: The Batch builder (which returns an array of batch title, operations, finished, etc., the batch definition as required by batch_set()), Batch operation callback (called by the batch API, handles batch administration and calls the Worker) and the Worker (which performs the actual task, but is not batch agnostic).
    In my opinion the Worker should not be aware of the batch. Making the worker batch aware makes unit testing and re-use in other contexts harder. I did not check how the current procedural code does or does not mix batch and worker, but I'm painting my ideal picture here. A service is probably the first choice for the worker, and the service may combine multiple workers (called by multiple batch operations).

    The question I'm raising here is whether we should (not) combine the Batch operation callback(s) and Batch builder into this Worker service. Worker, operation callbacks and builder in their own methods of course, but combined in one class. I did not find an OO pattern in core for Batch builder and Batch operation callbacks. I only found them in procedural code. As I mentioned above I lean towards _not_ combining them into the worker, but keep them separate (for re-use and unit testing). When choosing for separation, we can keep them procedural for now. But I 'd rather find an OO pattern for this too.

    This choice is not only relevant for this issue, but for all of Locale module's .inc files which are subject to refactoring in of #3215707: [META] Modernize Locale module.

    andypost’s picture

    @Sutharsan The batch builder already in core https://www.drupal.org/node/2875389 but its adoption a bit staled #2875151: [META] Implement Batch API as a service

    There's even #1797526: Make batch a wrapper around the queue system but I'm not sure it has enough chances to get in fast, OTOH locale could be first case to use it

    gábor hojtsy’s picture

    IMHO we should separate if the worker part needs to be reusable, eg. used in multiple batches or by contrib, or should be overridden as for what the worker does vs not how the batch is built (separation of concerns). Testing may be another good reason indeed that I did not think of before.

    daffie’s picture

    A couple of nitpicks about the new interface:

    1. +++ b/core/modules/locale/src/LocaleProjectStatusInterface.php
      @@ -0,0 +1,78 @@
      +  public function checkProjects(array $projects = [], array $langcodes = []);
      ...
      +  public function checkProjectsLocal(array $projects = [], array $langcodes = []);
      ...
      +  public function resetCache();
      

      Could we add ": void" to indicate that the method does not return anything.

    2. +++ b/core/modules/locale/src/LocaleProjectStatusInterface.php
      @@ -0,0 +1,78 @@
      +  public function buildProjects();
      ...
      +  public function remoteTranslationStatusOperations(array $projects, array $langcodes, array $options = []);
      

      Could we add ": array" to indicate that the method returns an array.

    3. +++ b/core/modules/locale/src/LocaleProjectStatusInterface.php
      @@ -0,0 +1,78 @@
      +   * @param array $options
      +   *   Batch processing options.
      ...
      +  public function remoteTranslationStatusOperations(array $projects, array $langcodes, array $options = []);
      

      The parameter is optional. Could we add "(optional)" to the parameter documentation.

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

    Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.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.

    needs-review-queue-bot’s picture

    Status: Needs review » Needs work
    StatusFileSize
    new144 bytes

    The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

    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

    Title: Convert locale.compare.inc to a service » [pp-1] Convert locale.compare.inc to a service
    Status: Needs work » Postponed
    nicxvan’s picture

    Title: [pp-1] Convert locale.compare.inc to a service » Convert locale.compare.inc to a service
    Status: Postponed » Needs work
    nicxvan’s picture

    I'm going to actually start fresh, the patch does not apply across 13 files and we've changed process, I'll review the patch for locations that functions landed.

    nicxvan’s picture

    Made it about halfway, haven't run CS so I won't do a MR since I know it will fail, but gotta take a break.

    nicxvan’s picture

    Issue summary: View changes

    nicxvan’s picture

    Issue summary: View changes
    Status: Needs work » Needs review
    claudiu.cristea’s picture

    nicxvan’s picture

    Thank you, I'll take that under consideration, but I think we don't want all of that overhead, another value object should be enough.

    We do have to figure out how to incorporate projectInfo since this also uses that.

    claudiu.cristea’s picture

    Assigned: Unassigned » claudiu.cristea

    Working on this. It's still far for completion

    nicxvan’s picture

    I added a couple of fixes and some comments, I'd like to chat about scope and what you think about the changes in LocaleSource.

    One nice thing is that we added LocaleSource in 11.4 so if we need to change something as long as we get it in before 11.4 we can change it a bit.

    nicxvan changed the visibility of the branch 3037031-locale-compare-combined to hidden.

    needs-review-queue-bot’s picture

    Status: Needs review » Needs work
    StatusFileSize
    new34.65 KB

    The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

    nicxvan’s picture

    Ok, let's see how this goes.

    I converted the object in LocaleSource to use the LocaleTranslatableProject object.

    There are some properties stored on that object that look like just LocaleFile properties but are used elsewhere.
    type is overloaded so I created a new property fileType to track.

    I created the properties on the class so we could just set them and see what we should do. We could maybe keep them short term, but I am not sure.

    There is a fairly complex conflation of LocaleTranslatableProject and LocaleFile between LocaleSource, locale_translation_update_file_history and locale_translation_status_save.

    I also deprecated LocaleProjectStorage and LocaleProjectStorageInterface.

    Most of the failures are due to using a deprecated service, but I think it's the alias:

    Drupal\locale\LocaleProjectStorageInterface:
        alias: 'locale.project'
        deprecated: The "%alias_id%" service is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use the 'Drupal\locale\LocaleProjectRepository' service instead.See https://www.drupal.org/node/3037033
    
    nicxvan’s picture

    Down to the dreaded functional failures:
    Fail locally:
    Drupal\FunctionalTests\Installer\InstallerTranslation
    Drupal\Tests\search_help\Functional\HelpTopicSearch
    Drupal\Tests\locale\Functional\LocaleConfigTranslationImport
    Drupal\Tests\locale\Functional\LocaleUpdateCron
    Drupal\FunctionalTests\Installer\InstallerExistingConfigSyncDirectoryMultilingual
    Drupal\Tests\help\Functional\HelpTopicTranslation
    Drupal\FunctionalTests\Installer\InstallerTranslationMultipleLanguageForeign
    Drupal\FunctionalTests\Installer\InstallerTranslationMultipleLanguageNonInteractive
    Drupal\Tests\locale\Functional\LocaleUpdate
    Drupal\FunctionalTests\Installer\InstallerTranslationMultipleLanguageKeepEnglish
    Drupal\FunctionalTests\Installer\InstallerTranslationMultipleLanguage
    Drupal\FunctionalTests\Installer\InstallerTranslationNonStandardFilenames
    Drupal\Tests\locale\Functional\LocaleTranslationChangeProjectVersion

    Passes locally:
    Drupal\Tests\locale\Functional\LocaleUpdateInterface

    nicxvan’s picture

    Down to just a few, a bunch of the tests failed due to conflated type and file type properties, we probably need to truly clean that up.
    I also removed readonly for now from the properties.

    Drupal\Tests\locale\Functional\LocaleUpdate
    Drupal\FunctionalTests\Installer\InstallerExistingConfigSyncDirectoryMultilingual
    Drupal\Tests\locale\Functional\LocaleUpdateInterface

    nicxvan’s picture

    Issue summary: View changes
    Status: Needs work » Needs review
    Related issues: +#3588483: Deprecating services that are autowired and autoconfigured doesn't quite work

    Ok I got this green, this is still kind of rough, but it's ready for a round of reviews.
    I imagine we want to try to better decide what to do about the repeated properties on LocaleTranslatableProject. Also a cleaner way to differentiate between the type on LocaleTranslatableProject and LocaleFile (They each have type, but the legacy code seemingly randomly overwrote the project type to the file type, I added a new fileType property to track, but it lead to much confusion.

    I also updated the CR.

    We also have to not trigger deprecation for LocaleProjectStorageInterface or add the deprecated key to the LocaleProjectStorageInterface service alias due to: #3588483: Deprecating services that are autowired and autoconfigured doesn't quite work

    I updated a bunch of other services to help fix some circular dependencies in LocaleFileManager and LocaleSource. I think these changes make this issue crucial to get into 11.4 if possible since those classes are not released yet and we'll avoid double deprecations.

    nicxvan changed the visibility of the branch 3037031-pp-1-convert-locale.compare.inc to hidden.

    nicxvan’s picture

    Issue summary: View changes
    nicxvan’s picture

    Issue summary: View changes

    nicxvan’s picture

    Ok I addressed almost all of the super straightforward stuff on the current MR, I updated the CR with those changes, but will need a new pass to make sure I didn't forget something especially if we go to the new MR.

    For the getProject, get, getMultiple etc I created a new MR since it's a behavior change, I think it's good minus a bit of messiness changing getAll behavior and needing to check if we need multiple or all. All of the get calls now populate the cache properly so a few tests don't work, it's also a new object, so the assert same won't work, I deleted some tests there and commented out two that we may want to discuss. Honestly this is probably better, why do we want to have out of sync projects and cache deleting a project?

    I think the two big remaining questions not addressed here fully:
    1. Do I go back to type and just document it can be extension type or file location type?
    2. Do we try to reuse the translatable project passed into LocaleSource or do we need a psuedo clone.

    nicxvan changed the visibility of the branch 3037031-locale-compare-same-project-source to hidden.

    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

    This is starting to really shape up!

    I addressed the most recent round of feedback and updated a few things too.

    This is ready again! I took a look at the IS and CR with the most recent changes.

    nicxvan’s picture

    Issue summary: View changes
    berdir’s picture

    We discussed the $source vs project stuff in LocaleSource and I proposed some changes to that, that essentially restore it almost exactly to HEAD and no longer merges those two things together. It's a weird split, they are overlapping and cloned from each other, but each has their own distinct properties and behaviors and I think we should not merge them. This allows us to remove several properties from LocaleTranslatableProject that were only used after being converted to a source. This also solves the type property conflict. Discussed that extensively in Slack.

    I will update the old follow-up #1842380: Convert $source object to a LocaleTranslationSource class to add a type for $source, we could revive that for that in a follow-up.

    That is and will likely remain my only direct code contribution to this MR, I think I'm still OK RTBC'ing this after it this been cross-reviewed.

    nicxvan’s picture

    Issue summary: View changes

    We discussed the changes in the previous comment before @berdir pushed them, I also reviewed the commits directly and the flow after.

    It's mainly scaling back some of the changes made here that really should be done in a follow up, @berdir already identified the follow up.

    I'll sign off on his changes, I think this is ready for review again, I've addressed all feedback!

    berdir’s picture

    Assigned: claudiu.cristea » Unassigned
    Status: Needs review » Reviewed & tested by the community

    Refactoring the locale module is really a challenge. There is so much code, complex value objects that are just so slightly different ($source vs $project, which this tried to unify but we undid that again), so many features and functions. The project storage is essentially a cache but comes with an extensive storage/new repository service that we slimmed down but still does a a lot. Sometimes the data is completely deleted and rebuilt (clicking the check manually button on the reports page), sometimes removed/uninstalled projects are just disabled, there is the sorting which I don't know what it's really used for and so many other things.

    We tried our best to find a middle ground between refactoring, using typed value objects, reducing the API service but also still somewhat limiting the scope here to be able to finish this. We have a number of follow-ups and I just filled #3589344: Remove the ability to have enabled/disabled projects in the locale project repository for the status stuff.

    This isn't perfect, but I think it's a reasonable improvement. and while the diff stats don't show that reduction in complexity/API surface (+ 828 − 320), that is mostly due to the old code only being deprecated. Once we can remove all the code in locale.compare and the old storage service, this should be roughly even again.

    Added one more comment and comment suggestion on the MR, but I think that's not holding up an RTBC.

    nicxvan’s picture

    Thank you! I updated the two comments after confirming your question.

    As you mentioned we still have a fair bit to do, but this is pretty good progress I think.

    We have the two follow ups you created and the plan for .module elimination (all of the batch functions are in the next issue, but based on how these have gone that might be ambitious).

    nicxvan’s picture

    Issue summary: View changes
    catch’s picture

    This all looks good to me, but one small question on the MR.

    • catch committed 2cc48834 on main
      task: #3037031 Convert locale.compare.inc to a service
      
      By:...
    catch’s picture

    Version: main » 11.x-dev
    Status: Reviewed & tested by the community » Patch (to be ported)

    Committed/pushed to main, thanks!

    Will need an 11.x backport MR, looks like services.yml and a test so hopefully not too bad.

    nicxvan’s picture

    Status: Patch (to be ported) » Reviewed & tested by the community

    The backport should be ready.

    The additional +2 are from needing autowire: true on the two new services.
    The additional -8 are from the deleted test difference (one of the reasons there wasn't a clean backport)

    The reasons we needed a backport:
    Services autowiring
    locale.translation.inc a use statement needed to be added
    bootstrap.inc the drupal_static_reset changes

    I compared the main commit with the backport and the changes are all the same.

    • catch committed 1629df58 on 11.x
      task: #3037031 Convert locale.compare.inc to a service
      
      By:...

    catch’s picture

    Status: Reviewed & tested by the community » Fixed

    Committed/pushed to 11.x, thanks!

    Now that this issue is closed, review the contribution record.

    As a contributor, attribute any organization that helped you, or if you volunteered your own time.

    Maintainers, credit people who helped resolve this issue.

    nicxvan’s picture

    I updated the previous CR.

    The only one that changed was https://www.drupal.org/node/3569330 for the locale_translation_get_projects deprecation.

    nicxvan’s picture

    quietone’s picture

    I published the recently reviewed change record.