Problem/Motivation

#3581303: Convert locale batch callbacks
See:

locale.module

  • LOCALE_JS_STRING
  • LOCALE_JS_OBJECT
  • LOCALE_NOT_CUSTOMIZED
  • LOCALE_CUSTOMIZED
  • LOCALE_TRANSLATION_USE_SOURCE_LOCAL
  • LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL
  • LOCALE_TRANSLATION_DEFAULT_SERVER_PATTERN
  • LOCALE_TRANSLATION_STATUS_TTL
  • LOCALE_TRANSLATION_OVERWRITE_ALL
  • LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED
  • LOCALE_TRANSLATION_OVERWRITE_NONE
  • LOCALE_TRANSLATION_REMOTE
  • LOCALE_TRANSLATION_LOCAL
  • LOCALE_TRANSLATION_CURRENT

Proposed resolution

Deprecate the constants and replace them according to the following table:

Deprecated constant Replaced by
LOCALE_JS_STRING moved as local variable to LocaleJs::parseJsFile()
LOCALE_JS_OBJECT moved as local variable to LocaleJs::parseJsFile()
LOCALE_JS_OBJECT_CONTEXT moved as local variable to LocaleJs::parseJsFile()
LOCALE_NOT_CUSTOMIZED moved to LocaleDefaultOptions::NOT_CUSTOMIZED
LOCALE_CUSTOMIZED moved to LocaleDefaultOptions::CUSTOMIZED
LOCALE_TRANSLATION_USE_SOURCE_LOCAL \Drupal\locale\Model\TranslationUpdateMode::Local
LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL \Drupal\locale\Model\TranslationUpdateMode::RemoteAndLocal
LOCALE_TRANSLATION_STATUS_TTL inlined in TranslationStatusForm
LOCALE_TRANSLATION_OVERWRITE_ALL \Drupal\locale\Model\Overwrite::All
LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED \Drupal\locale\Model\Overwrite::NonCustomized
LOCALE_TRANSLATION_OVERWRITE_NONE \Drupal\locale\Model\Overwrite::None
LOCALE_TRANSLATION_REMOTE \Drupal\locale\Model\SourceType::Remote
LOCALE_TRANSLATION_LOCAL \Drupal\locale\Model\SourceType::Local
LOCALE_TRANSLATION_CURRENT \Drupal\locale\Model\SourceType::Current

LocaleTranslationSource now has three helpers:
getType will return the SourceType enum.
getFile will return the file for the current type.
isUpdateAvailable returns true if the type is local or current.

Remaining tasks

Follow ups:
#3619927: [pp-1] Properly handle exceptions in PoDatabaseWriter
#3619926: [pp-1] Review replacing the 600 ttl for translation timeout

User interface changes

None.

API changes

New enums, see above.

Data model changes

None.

Issue fork drupal-2831617

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

mpdonadio created an issue. See original summary.

mpdonadio’s picture

Title: Deprecate global constants in local module » Deprecate global constants in locale module
Issue summary: View changes

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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.

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.

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.

gábor hojtsy’s picture

Reparenting to #3215707: [META] Modernize Locale module where it has more likeliness to be fixed now. I think this may be resolved piece by piece as various include files and global functions that use the constants become services. So it may be that no direct work will be needed in this issue.

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.

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.

nicxvan’s picture

Issue summary: View changes
claudiu.cristea’s picture

I think grouped constants should be moved to backed enums:

For instance LOCALE_TRANSLATION_USE_SOURCE_LOCAL and LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL:

enum LocaleSourceType: string {

  case Local = 'local';
  case RemoteAndLocal = 'remote_and_local';

  public static function asOptions(): array {
    return [
      self::Local->value = t('Drupal translation server and local files'),
      self::Local->value = t('Local files only'),
    ];
  }
}

Same for LOCALE_TRANSLATION_OVERWRITE_* and LOCALE_TRANSLATION_* and LOCALE_TRANSLATION_SOURCE_COMPARE_*

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea

Let's try...

claudiu.cristea’s picture

Version: 11.x-dev » main
claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes

Update IS

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Update IS

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Updated the CR

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Issue summary: View changes
nicxvan’s picture

I'd propose that the constants in locale.translations.inc

  • LOCALE_TRANSLATION_SOURCE_COMPARE_LT
  • LOCALE_TRANSLATION_SOURCE_COMPARE_EQ
  • LOCALE_TRANSLATION_SOURCE_COMPARE_GT

Be addressed in: #3569328: Modernize locale.translations.inc
It keeps everything nicely self contained.

claudiu.cristea’s picture

Did some progress but I still need to reflect on BC. This issue is part of modernizing Locale meta, and I think we need some refactoring not only moving the code around.

claudiu.cristea’s picture

Issue summary: View changes

Updating IS

claudiu.cristea’s picture

Issue summary: View changes

claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned
Issue summary: View changes
Status: Active » Needs review

This is ready for review

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Issue summary: View changes
nicxvan’s picture

Couple of questions, I didn't finish my review.

nicxvan’s picture

Title: Deprecate global constants in locale module » [pp-3] Deprecate global constants in locale module
Status: Needs review » Postponed (maintainer needs more info)

Postponing on #3577671: Modernize locale file handling #3037031: Convert locale.compare.inc to a service and the batch conversion in .inc I haven't created yet.

I spoke briefly with @claudiu.cristeau about the overall order and he agreed this is ok.

nicxvan’s picture

Title: [pp-3] Deprecate global constants in locale module » [pp-2] Deprecate global constants in locale module
nicxvan’s picture

Title: [pp-2] Deprecate global constants in locale module » [pp-1] Deprecate global constants in locale module
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Postponed
nicxvan’s picture

Looking at what remains, this is actually the easiest to do, we should probably do this last since it won't require any dependency injection changes.

nicxvan’s picture

nicxvan’s picture

Title: [pp-1] Deprecate global constants in locale module » Deprecate global constants in locale module
Assigned: Unassigned » nicxvan
Status: Postponed » Needs work

I began working through updating this.

I'm doing it from scratch solved most has changed, but I'm using the CR as a template.

I mostly agree, the local constants on the setting form I changed to an enum since they are used in tests, I noticed a few weren't directly changed since I assumed you didn't want dependencies.

I'm not sure that's the right route, but I've generally been following that too.

I tweaked some naming, I assigned myself so I can finish in the morning.

nicxvan’s picture

Status: Needs work » Needs review

It actually ended up being quite a bit smaller with the refactoring that has happened since.

I went with backed enums for consistency in all cases, that also allowed us to drop the update hook.

daffie’s picture

Status: Needs review » Needs work

nicxvan’s picture

I created a third option where I replaced the customized constant with an enum so it's easier to see where it is.

nicxvan changed the visibility of the branch 2831617-locale-constants-v2 to hidden.

nicxvan’s picture

Status: Needs work » Needs review

OK I changed the two tests, they already have a soft dependency on locale, so adding the enum there is fine.

I also added the two helpers suggested by @berdir, it cleans up quite a bit.

I created a follow up: #3619605: Clean up current workflow for locale source, also clean up saveSource

I'll update the CR and IS in the morning if this makes sense.

feuerwagen’s picture

Issue summary: View changes

Updated the replacement table to reflect the current state of the MR

nicxvan’s picture

Issue summary: View changes

Thanks @feuerwagen!

I updated it again just now to match what I just pushed up.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new2.62 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

Status: Needs work » Needs review

mondrake made their first commit to this issue’s fork.

berdir’s picture

Status: Needs review » Needs work

Did another full pass, hopefully after that I can RTBC.

mondrake’s picture

As to the why we had transaction deprecations in the previous MR, that is due to PoDatabaseWriter::writeItems() missing to handle an exception if that occurs during the transaction. A transaction is opened, then because of the SQL error due to

SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'customized' at row 1

an exception is thrown, but not managed. So it bubbles up and when the transaction object is losing scope, a commit-on-destruct is attempted and the deprecation thrown. I daresay that is a bug, because in general you may end up having only partial translations (if I understand the code here).

With explicit transaction commit, we now need to be carefully dealing with the unhappy path as well as with the happy one.

I enclosed the operations occurring during the transction in a try...catch construct, so that if a Throwable is occurring during the transaction the entire db transaction is rolled back, and now the deprecations are gone.

This opens an interesting question @catch @daffie - once we eventually remove the commit-on-destruct code, what shall we leave in its place? Do we still throw an out-of-order transaction exception to notify developers they have mishandled the db transaction, or do we simply silently rollback it (which is PHP's default behavior)?

nicxvan’s picture

Status: Needs work » Needs review
nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Issue summary: View changes
berdir’s picture

Status: Needs review » Reviewed & tested by the community

I think this is pretty OK now.

If I could pick, I'd rather do some more work on other cleanup, deprecation and refactoring issues which will likely reduce the number of constants we have/need. The SourceType for example might eventually just go away completely or at least become all internal to the TranslationSource object.

But this is one of the last two issues to fully deprecate the .module file, semi-blocking the formal deprecation of .module files, which we want to get done asap. We can also do the cleanup and refactoring issues after this, doesn't make those harder, at worst it results in some confusing double deprecations over time.

The decision when to use an enum vs class constants is not entirely obvious in cases, could go either way. And we didn't want to deal with changing API's too much that we'll likely refactor further or away completely in other issues, such as saveSource(), nor does it seem worth the hassle to convert the settings config object to use enum objects directly and deal with BC around that.

  • amateescu committed 39b62a82 on main
    task: #2831617 Deprecate global constants in locale module
    
    By: nicxvan...
amateescu’s picture

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

Committed and pushed 39b62a8288e to main. Thanks!

Needs a rebase for 11.x.

Haven't published the CR yet, I'll wait for the 11.x commit.

nicxvan’s picture

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

The conflict was the constant deprecations, so it was an easy resolution.

There were also three usages in 11.x not on main:
https://git.drupalcode.org/project/drupal/-/merge_requests/16930/diffs?c...

  • amateescu committed d1859047 on 11.x
    task: #2831617 Deprecate global constants in locale module
    
    By: nicxvan...
amateescu’s picture

Status: Reviewed & tested by the community » Fixed

The backport looks good :) Committed d185904 and pushed to 11.x. Thanks!

Published the CR as well.

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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.