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.
Overcoming arbitrary line lengths of .po translations
...have you ever received a merge request for source containing changed .po-files?
Proposal
Option which makes translation export seek to keep translations single-lined instead of splitting them in parts of maximum 70 chars.
Limitation
Converted .po-files must be importable by core.
Thus lines cannot be longer than 10 * 1024 minus room for gettext context (e.g. msgid_plural);
10 * 1024 maximum defined in _locale_import_read_po().
For full reasoning, and a drush script which converts existing .po files
See potx issue drush script to ease .po revision diffing.
Comment | File | Size | Author |
---|
Comments
Comment #1
jacobfriis CreditAttribution: jacobfriis commentedPatch for D7.
And then:
drush vset locale_export_prefer_single_lined 1
Comment #2
jacobfriis CreditAttribution: jacobfriis commentedComment #3
cilefen CreditAttribution: cilefen commentedI do not know much about translations, but could this be an improvement to Drupal 8 as well?
Comment #4
jacobfriis CreditAttribution: jacobfriis commentedYes, it certainly would be an improvement to D8 too.
But I cannot figure out where the max. line length (if any) of translation import is defined in D8. Kind of get lost in the import bulk operation ;-)
Setting the max. for export is 'easy' and would have to be done here:
Without knowledge of the max. line length for import (if any) it would be hazardous to increase the max. for export.
So I would like to see if there's any interest in the issue, before venturing into more research. But if I stumble upon the solution (import max.?) then I will for sure make a D8 patch too ;-)
Comment #5
cilefen CreditAttribution: cilefen commentedActually, if this is a D8 issue, according to the backport policy, it must be fixed in 8.0.x-dev (or 8.1.x-dev if it is disruptive) first. If that is the case, the version on this issue should be changed.
Comment #6
jacobfriis CreditAttribution: jacobfriis commentedSo I should wait untill someone cares and figures out how to fix it in D7?
Look, we've got some production sites out there in the real world, which need this fix, and which are D7 based.
Currently there only exists a patch for D7, and none for D8. So it makes perfectly sense to keep the issue as D7 until someone figures out how to fix in D8. And BTW you cannot run an automated test of a D7 patch against D7 codebase if the issue is set on D8.
Not having read those policies, I'm still sure that it's perfectly alright to find and fix D7 issues as such - even if the same issue exists in D8.
If you have a fix: change the issue to D8 status and upload the patch ;-)
Comment #7
jacobfriis CreditAttribution: jacobfriis commentedSorry, really didn't mean to be rude. But the thing is, if we turn it into a D8 issue now, we'll have to hide the D7 patch - otherwise the D7 patch will auto-magically get tested against D8, and fail.
And if we hide the D7 patch, then folks can't see that there - at least - exists a D7 patch.
So it's a bit catch-22'ish ;-)
I will look into the matter for D8 within a week or so. And if I find a solution, I'll naturally switch the issue to D8.
But currently it wouldn't be constructive, as far as I see it.
Comment #8
cilefen CreditAttribution: cilefen commentedThe availability of a patch is not a consideration as to which branch an issue should be in. I am trying to help. This issue will not be committed to Drupal 7 first if it exists in Drupal 8. From the policy:
I know practically nothing about translations in general so I have nothing to say about it but it looks like Drupal 8 continues with .po files so this could be an issue with it.
Comment #9
jacobfriis CreditAttribution: jacobfriis commentedAye, I get your point. It shan't expect the D7 patch to merged into the D7.
And yes, as it turns out, I actually committed an infringement against policies. I really didn't know that.
So I won't do that again. Next time I have a fix to an issue (which isn't a security matter etc.) of D7 but don't have a fix to D8 I'll just have to sit on it, or release off-drupal.org.
But I cannot undo things now.
Comment #10
cilefen CreditAttribution: cilefen commentedPosting the patch is good! It will certainly help.
Comment #11
jacobfriis CreditAttribution: jacobfriis commentedPatch for D7 at #1.
Solution for D8 not found yet due to uncertainty about max. line length for D8 translation import (#4).
Comment #12
jacobfriis CreditAttribution: jacobfriis commentedThere seem to be no max. line length for translation import
So a quick-n-dirty would be:
But that's for sure not the correct way to do it. No component class uses configuration like that.
Instead you'ld probably extend PoStreamReader and override readLine(). But I have no idea how you tell we should the overriding class ;-)