Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Currently how we check for updated translations and then actually update the translations is baked into controllers and forms in the Interface translation module. This makes it hard to provide the functionality through non-HTML means, for example Drush. See https://github.com/drush-ops/drush/pull/1818Proposed resolution
Provide a service for high-level translation update functions.
Remaining tasks
Agree on the scope.- Write tests.
Write and check code.Write change record.
User interface changes
None.
API changes
A new service that wraps existing procedural code.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#62 | interdiff_60-62.txt | 8.35 KB | vsujeetkumar |
#62 | 2631584_62.patch | 32.01 KB | vsujeetkumar |
#60 | interdiff_58-60.txt | 2.84 KB | vsujeetkumar |
#60 | 2631584_60.patch | 23.4 KB | vsujeetkumar |
#58 | interdiff_56-58.txt | 3.81 KB | vsujeetkumar |
Comments
Comment #2
tstoecklerJust to get the ball rolling. This should be 100% backwards compatible, so tagging for 8.1.x. The only possible breaks are the constructor changes in the form and controller but we do not treat those as APIs.
Comment #3
tstoecklerComment #4
Gábor HojtsyLooks good to me. Makes sense to API-ify this.
Comment #5
tstoecklerSome additional newlines, can maybe be fixed on commit (or not TBH, I guess it's not a big deal...).
Comment #6
catchThis could use the locale.project service.
Also this is quite sad (and the includes in ::update() below) - is there an issue we can link to for moving that functionality to a class too?
Comment #7
naveenvalechaAddress #6.1
#6.2 looks like there is already one. is this is one #1834298 ?
Comment #10
Kristen PolThanks for the patch! I reviewed the code and noticed a few minor things.
Plural change: project => projects.
Typo: an => and.
Nitpick: Over 80 characters.
Nitpick: Extra line.
Missing semi-colon?
Missing semi-colon?
Comment #11
Kristen PolWhat is the best way to test this?
Comment #12
tstoecklerOn a site with Interface Translation enabled you should click the "Check manually" link on the "Available translation updates" screen. That is the
check()
part. Assuming there are translation updates, importing them through the UI tests theupdate()
part. In both cases there should be no change before and after the patch and everything should just work as this is merely a refactor to allow Drush (or other scripts) to be more sane.Comment #13
tstoecklerOh, and thanks for the review.
I will try to get back to this, but...:
Re #6 in theory I agree, that the current code is still suboptimal but if you look at the actual code that is being called you will see the giant spaghetti monster that
locale.module
is. That is not to insult anyone who worked on locale, in fact the amount of features we were able to add to it, before the New World Order (tm) kicked in is quite impressive. Also Batch-non-API (again, no offense) doesn't help but instead is its own spaghetti monster fighting against the one that it Locale. So at the moment it is not easy to much more of a refactor other than #2/#7 complete refactoring the whole module and Batch API entirely. I.e. even adding a @todo is rather hard, unless I open an issue with the title "Refactor Locale module", with issue summary "@todo" (and postponed on an issue "Refactor Batch API"), which seems rather pointless to me. I had originally planned to submit a little bit nicer code in #2 but then ended up failing due to the above point.Comment #14
Kristen PolI tested the patch on a local site. The check is fine. I'm having a hard time testing the manual update since there aren't new translations since the last update.
One thing I noticed when testing is that if I choose:
Overwrite existing translations.
for:
Import behavior
it does not affect doing a manual update. The description does say it's for "automatic" updates:
How to treat existing translations when automatically updating the interface translations.
but that doesn't seem very intuitive to me. Why should a manual update behave differently than an automatic update?
I was hoping that I could check the update by:
But since manual vs automatic updates behave differently then I can't test this way. I'm unclear how else I can test without mucking with the database directly since I don't have an D8 site that is old enough to have some missing translations but not old enough that it's not on a way older version of D8.
Thoughts?
Comment #15
Gábor HojtsyWhich URL did you run the manual updates from? Which admin page?
Comment #16
Kristen PolI have found the link I used. Go to:
/admin/config/regional/translate/settings
and it has a link with text:
Check updates now
and if you click that it does the check and you end up on:
/admin/reports/translations
which also has a:
Check manually
link that does the same thing. The link is linked to:
/admin/reports/translations/check
I'll see if I can reproduce the issue of manual vs automatic update difference and open a new issue if I can reproduce.
Comment #17
Kristen PolAlso, it's possible that this is because there are no updates so it's not changing back my custom translations. If so, then it might apply to both manual and automatic updates. That would be a different issue.
Recap: There appear to be 2 possibilities:
1) The custom translations aren't wiped out for manual updates but are for automatic.
or
2) The custom translations aren't wiped out for manual or automatic updates when there are no new translations from localize.drupal.org.
My feeling now is it's the latter. I'll be doing some testing locally to see if I can figure that out.
Comment #18
andyposta lot of procedures without wrappers
Comment #19
Gábor Hojtsy@Kristen: yeah I can imagine it sees the .po files don't need updating and it does not reimport them since they were not updated, therefore not overwriting your customizations even though you wanted that. That sounds very plausible :)
Comment #20
Kristen PolI have confirmed that it was scenario 2 in #17 as I added a bunch of languages locally yesterday, changed the same translations for 3 strings for all languages, and just now ran a manual update. There was an update for Italian and that updated the custom Italian strings but the other languages are unchanged. I guess that kind of makes sense unless you want force getting the latest strings. But, then I guess you can do the manual po files though that's kind of a pain.
The good thing is that it worked so the patch is fine from that perspective. But, now I see #18 so maybe it needs to be updated?
Comment #21
tstoecklerFixed the reviews and tried one more time to remove some of the function calls. Like I tried to explain above I'm not touching those related to batch API. Without an OO batch API we need to call batch API anyway, so I don't see much value in that.
When I had to inject the translation updater into locale's import form I wondered whether that is actually a good place to put the
getDefaultOptions()
method. It seems there could be a separate translation importer, that the form should use and that the translation updater should inject. What do people think?I just realized I named the interdiff wrong, but it should have the correct contents.
Comment #23
penyaskitoI love the idea, but probably worth to do it in a follow-up issue.
I would love to have this in core, which we can iterate later.
Nitpicks:
We don't want those anymore.
Coder complains about the extra empty line in this docblock.
Comment #24
tstoecklerHere we go.
Comment #26
tstoecklerLearned something new today: A module's classes are not available when including the .module file. So reverted those constant changes.
Comment #27
Kristen PolI tested the patch from #26 using the steps from #16 and got no errors. I checked the interdiffs from #26 and #24 and do not see anything wrong and see that #24 interdiff addresses items from #23. Marking RTBC.
Comment #28
andypostShould be properly deprecated
@deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0.
Comment #29
Kristen PolThanks for the review. I have updated the patch with the changes from #28.
Comment #30
Kristen PolComment #32
penyaskitoThanks! Patch looks good, but 8.2.0 was already released (sorry for the late review). We should change this. Otherwise looks good to me. We will need a change record too.
Comment #34
Gábor HojtsyAnyone planning to pick this up today for Global Sprint Weekend?
Comment #35
tstoecklerWriting a change notice now.
Comment #36
tstoecklerKept the change notice generic, so we can add more functions to it when we deprecate more stuff. To be perfectly honest, I actually did it this way because I thought we were deprecating more functions. Obviously feel free to rewrite.
Comment #37
tstoecklerComment #38
Gábor HojtsyComment #40
Sutharsan CreditAttribution: Sutharsan at LimoenGroen commentedRe-rolled the patch. It did no apply due to the array syntax change.
Comment #41
Sutharsan CreditAttribution: Sutharsan at LimoenGroen commented- Changed the version in the deprecation info to 8.5.0
- Changed the deprecated REQUEST_TIME to time::getRequestTime(). Don't think it is good to put deprecated stuff in the new TranslationUpdater class.
Comment #42
Sutharsan CreditAttribution: Sutharsan at LimoenGroen commentedRerolled the patch.
Comment #43
Sutharsan CreditAttribution: Sutharsan at LimoenGroen commentedComment #44
tstoecklerThanks @Sutharsan for picking this up!!!
Moving back to RTBC per #27. Even though I contributed to this patch since #27 only minor commend adjustments were requested and those have been updated, so I think it's fair for me to re-RTBC this.
Comment #45
tstoecklerAhem.
Comment #46
Sutharsan CreditAttribution: Sutharsan at LimoenGroen commentedOh, sorry to spoil the party, but I had a pending review I just couldn't finish this morning.
Checked that deprecated constants and function are not used anywhere on core.
Checked comments of new class, interface, constants, methods.
Some things to work on though...
This should not be modified in this patch. It is not used in the TranslationUpdater server and it is not part of the high level update proces but it is used in the check/fetch process.
Version in deprecation text is not correct.
Comment incorrect. It _does_ check whether translation updates are available. But only if previous check was executec more than 10 minutes ago (TranslationUpdaterInterface::STATUS_TTL).
Comment #47
Sutharsan CreditAttribution: Sutharsan at LimoenGroen commented#46 comments processed.
Comment #48
langelhc CreditAttribution: langelhc at Skilld commentedI found that 'instead' word is duplicated on local.module
Comment #51
cilefen CreditAttribution: cilefen at Institute for Advanced Study commentedComment #55
Kristen PolThe patch needs a reroll if this issue is still relevant (I asked in the #multilingual Slack channel but no one chimed in).
Comment #56
vsujeetkumar CreditAttribution: vsujeetkumar at Srijan | A Material+ Company for Drupal India Association commentedRe-roll patch created, Please have a look.
Comment #57
Kristen PolTake a look at the "15 coding standards messages" noted here:
https://www.drupal.org/pift-ci-job/1769855
Comment #58
vsujeetkumar CreditAttribution: vsujeetkumar at Srijan | A Material+ Company for Drupal India Association commented@Kristen Pol Fixed the "coding standards messages", Please have a look.
Comment #59
Kristen PolThanks for the update. Sorry, I should have looked at the patch prior to comment #57.
I only scanned the patch for obvious issues and did not review for the approach as it was reviewed above by @tstoeckler and @Sutharsan. The only obvious thing that that needs changing are the versions:
Change versions to
9.1.0
and10.0.0
, e.g.@deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.
Same as above.
Same as above.
Same as above.
Same as above.
Same as above.
Same as above.
Also, it would be good to double check that I didn't miss any of these.
Comment #60
vsujeetkumar CreditAttribution: vsujeetkumar at Srijan | A Material+ Company for Drupal India Association commented@Kristen Pol changes has been done according to #59, Please have a look.
Comment #61
Kristen PolThanks for the update. The changes address #59.
Now we need to see if tests come back green.
Comment #62
vsujeetkumar CreditAttribution: vsujeetkumar at Srijan | A Material+ Company for Drupal India Association commented@Kristen Pol, Fixed the test, Please review.
Comment #63
Kristen PolThanks for the update.
1) I was confused why the interdiff was so large and then I went back through the old patches and see that the class and interface you added were there back in #48 and then got accidentally removed in #56. I compared the new patch with #48 and the differences seem ok:
a) Changed
@deprecated in Drupal 8.5.0, will be removed before Drupal 9.0.0.
to@deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.
as requested in #59.b) Added
@see https://www.drupal.org/node/2847622
which is the change record that was created in 2017 (!). This was added starting in patch #58.Note that I just updated the change record to reference the 9.1.x branch.
c)
drupal_set_message
is switched to$this->messenger()->addStatus
due to deprecation.d)
$this->url
was changed toUrl::fromRoute
due to deprecation.2) Tests pass.
3) Code was reviewed previously by @tstoeckler and @Sutharsan.
4) I've updated the issue summary to strike out what I know has been done. What I'm unclear about is if additional tests need to be added as the issue summary says to write tests yet the "Needs tests" tag was never added and there aren't any comments about writing tests.
5) Tagging for manual testing as it's probably good to double check this even though automated tests passed.
Comment #64
Kristen PolI tested this as following. At first I was going to try to wait for awhile to see if translations were added to test the update part but I found a way to cheat.
1) Add a language but very quickly use the browser back button so that it doesn't pull over the translations
2) You see a message the language was added
3) Go to /admin/reports/translations
4) Click
Check manually
link5) You will see that there are translations available
6) Click
Update translations
button7) Translation will be added
8) Go to /admin/config/regional/translate/settings
9) Click
Check updates now.
link10) You will see that the projects were checked
This worked as expected. Moving back to needs work for tests in case more need to be added.
Comment #68
mglamanWhen, if, this lands: we will need phpstan-drupal to be explicitly updated to check for these constants in https://github.com/mglaman/phpstan-drupal/blob/main/src/Rules/Deprecatio...