Problem/Motivation
There's no translation:// stream wrapper for translation files, like there is for public:// and private://, even though it's configured the same way and in the same place, leading to inconsistencies and uncertainly about how to access these files correctly.
Proposed resolution
Write a stream wrapper like the one for public:// and private:// - make sure it's used consistently that all value saved to the locale_file table is the translate://local.po format.
As locale_file table isn't migrated from D7, not update patch needed.
Remaining tasks
The #37 patch needs a bit more work, but seems to be close, except for a few edge-case tests.
User interface changes
None
API changes
Locale directory reference should now use the wrapper
Basically all references like this should be updated to use the wrapper:
$directory = variable_get('locale_translate_file_directory', conf_path() . '/files/translations');
Original report by penyaskito
It would be great having a translations:// stream wrapper, decoupling code that needs to know about these files from the variable name where the folder is being stored. This is line with existing public:// and private:// wrappers to improve developer experience and consistency. The translations file directory is even configurable on the same screen that the rest of the file system paths.
Comment | File | Size | Author |
---|---|---|---|
#71 | translations-stream-wrapper-1658842-69-71.interdiff.txt | 2.14 KB | webflo |
#71 | translations-stream-wrapper-1658842-71.patch | 9.25 KB | webflo |
#69 | translations-stream-wrapper-1658842-69.patch | 9.31 KB | webflo |
#67 | i1658842-67.patch | 9.23 KB | penyaskito |
#63 | i1658842-63.patch | 10.36 KB | penyaskito |
Comments
Comment #1
penyaskitoSome starting code is at #1635084: Track import status of files in the locale .po file directory.
Comment #2
Gábor HojtsyRetitling. Note that this was suggested by @rfay and discussed with a few people on IRC as a better way to manage files in the translations directory instead of relying on conf_path() and variable_get() all the time. This is in line with public:// and private:// which are also stream wrappers for configured directories. The .po translations file directory is configured the same way and for DX it makes sense to have a stream wrapper for it as well.
Comment #3
penyaskitoI'm not very happy with this. For keeping the tests green, I need to process the output of file_scan_directory in locale_translate_get_interface_translation_files.
Not sure if it's the path we should follow. If the answer is yes, we need to provide a hook_update_N implementation for updating the locale_file table.
Comment #4
penyaskitoComment #5
penyaskitoRerolled.
Comment #6
penyaskitoOops, it was empty.
Comment #8
Gábor HojtsyIs it not possible to file scan directory with translations:// as the directory? That should get you those paths back, no?
Comment #9
attiks CreditAttribution: attiks commentedDo we need the assignment?
add/remove public
use StreamWrapper
Comment #10
Gábor HojtsyStill interested in working on this?
Comment #11
penyaskitoYeah, I'll do a last attempt on the sprint :)
Comment #12
penyaskito@attiks: Seems like it is not possible. Related: #1714654: file_scan_directory() does not work with a stream wrapper and empty (or root) path "foo://".
I'm taking care of your other comments, thanks for reviewing.
Comment #13
penyaskitoTranslation tests work by now. Haven't launch others, let's see what testbot thinks.
Comment #14
Gábor HojtsyLooks generally good to me. Would be good to have a stream wrappers expert look at this. Hm.
Comment #16
penyaskitoOne of the things that make me doubt is if we should follow saving translation paths (/var/www/sites/default/files/translations/one.hu.po) or we should be saving the uri (translations://one.hu.po) into the locale_file table.
All failing tests are because of having mixed the two schemes, and I don't know if the right path should be using drupal_realpath around the uri when comparing to db in tests, or saving the files with the uri scheme prefix.
The second path looks more clean for me, and makes possible to change the location with only changing a variable (let's say, I decide to put my translations under source control in an existing project, but I don't want to put sites/default/files under SCM).
Marking as needs review for discussion.
Comment #17
attiks CreditAttribution: attiks commentedDon't store the real path, it might change if you deploy a site, I'm all in favor of storing either
translations://one.hu.po
orone.hu.po
since the goal is to always usetranslations://
If we want to go for consistency we should store
translations://one.hu.po
, file_managed does the same (ex.public://Curve.jpg
)Comment #18
Gábor HojtsyAgreed with attiks.
Comment #19
Gábor HojtsyComment #20
chx CreditAttribution: chx commentedWhy is getExternalUrl implemented? This is completely new code and I do not see a reason of its existence. Do we want to provide external , browser-accessible URLs to po files??
I completely agree with the realpath removal.
Comment #21
Gábor HojtsyI don't think we wanted to provide public access to the .po files.
Comment #22
attiks CreditAttribution: attiks commented#20 I think the original idea was to be able to download .po files from an external location
Comment #23
Gábor HojtsyYeah, well, sites should not really make their .po files available for download. At least our htaccess used to have access deny patterns to avoid .po files being downloaded from sites, which might or might not have been removed. It is supposed to be internal data on sites. They might download it from remote sites, but they would not make it available for download.
Comment #24
attiks CreditAttribution: attiks commented@Gábor agreed!
Comment #25
penyaskitoAddressing comments at #20. Needs an upgrade path for existing PO files into the locale_file.
Comment #26
penyaskitoComment #27
Gábor Hojtsylocale_file is not present on Drupal 7, so unless we want to have an l10n_update => D8 core upgrade path, we don't need to touch the data, since the table will be new and empty with D8. I don't remember if we did the l10n_update => D8 upgrade path or not when introducing it.
Comment #29
penyaskitoI was looking at that right now with a D7 install.
Removing the tag then, because locale_update_8010 creates the table and no data is migrated from l10n_update, so no data needs to be updated.
Comment #30
penyaskitoBack to needs work.
Comment #31
penyaskitoComment #33
penyaskitoComment #35
penyaskitoI have clues about how to fix this, but I won't be able of working on this before tomorrow evening. Leaving unassigned if anyone wants to work on it during morning sprint.
My branch is already at the D8MI sandbox, it's called streamwrapper-translations-1658842.
Comment #36
penyaskitoAssigning back to me.
Comment #37
penyaskitoWhen we do low-level operations to files, we must do it with the real filepath. I didn't expect this from streamwrappers, or we are doing anything wrong here.
Comment #39
BrockBoland CreditAttribution: BrockBoland commentedNeeds issue summary
Comment #39.0
BrockBoland CreditAttribution: BrockBoland commentedUpdating rationale.
Comment #40
twomasc CreditAttribution: twomasc commentedWrote issue summary
Comment #41
twomasc CreditAttribution: twomasc commentedRemoving "Issue summary initiative" tag
Comment #42
attiks CreditAttribution: attiks commentedI'm doing some debugging:
'translations://po_u0Ip1X.po' maps to '/var/aegir/platforms/drupal8git/core/modules/locale/tests/po_u0Ip1X.po' which can not be right
Comment #43
attiks CreditAttribution: attiks commentedpatch for testbot, problem was that the tests were using /core/modules/locale/tests as directory, but that isn't writeable.
Comment #45
penyaskito@attiks, that's right when testing importing files, but not when testing dumping files. We need to set the variable in those cases, but take care that setup does that for you and is not valid for both cases.
Comment #46
attiks CreditAttribution: attiks commentedfixed importstatus test and added missing file
Comment #47
attiks CreditAttribution: attiks commentedpatch without colors
Comment #48
attiks CreditAttribution: attiks commentedcan go away
Comment #49
attiks CreditAttribution: attiks commentedcan go away
Comment #51
tobiasb#47: i1658842-45.patch queued for re-testing.
Comment #53
attiks CreditAttribution: attiks commentednew patches
Comment #55
webflo CreditAttribution: webflo commented$dir is a undefined variable. Do you mean $destination? The default value for locale_translate_file_directory is conf_path() . '/files/translations' already. Why do you set it?
Lets prepare the directory in the setUp method.
Same as the first comment.
Comment #56
attiks CreditAttribution: attiks commentedcomments fixed
Comment #58
attiks CreditAttribution: attiks commentedgo bot!
Comment #59
attiks CreditAttribution: attiks commentedComment #60
attiks CreditAttribution: attiks commentedComment #61
penyaskitoSo for me it is RTBC.
Comment #62
attiks CreditAttribution: attiks commentedWe detected some problems in #1751326: When locale import happens on module enable, many notices are thrown that are more related to this patch, so back to NW
Comment #63
penyaskitoThe only problem I've found is a notice like
This is fixed in the attached patch.
Interdiff:
Comment #64
attiks CreditAttribution: attiks commentedSo lets move this one forward and handle the other problems in #1751326: When locale import happens on module enable, many notices are thrown once this is committed
Comment #66
webchickOk, as of today we are once again under thresholds, so 8.x features are on the table again. Yay!
Unfortunately, this patch no longer applies. :( Can we get a quick re-roll? In looking through, I couldn't find anything to complain about, so feel free to mark RTBC again once this is done.
Comment #67
penyaskitoLooks like the streamwrapper class itself has been commited before by accident.
If testbot pass is RTBC.
Comment #69
webflo CreditAttribution: webflo commentedRerolled the patch from penyaskito in comment 63.
Comment #70
webflo CreditAttribution: webflo commentedI think its better to use the 'translations://' stream wrapper here.
Comment #71
webflo CreditAttribution: webflo commentedGo testbot!
Comment #72
Gábor HojtsyWas RTBC 4 days ago before rerolls and minor improvements, the streamwrapper class is already committed, so better commit the rest :)
Comment #73
attiks CreditAttribution: attiks commentedWebflo, thanks for following up
Comment #74
webchickYea, sorry about that. :P
I reviewed this already at one of the D8MI sprints, and it looks good to me. COmmitted and pushed to 8.x. Thanks!
Comment #75
Gábor HojtsyI've updated the changelog at http://drupal.org/node/1352228 to refer to this issue as well, and updated the code example there to show usage example of the new stream wrapper. This should be fully done then :) Thanks all!
Comment #76
jbrown CreditAttribution: jbrown commentedShouldn't it be translation:// instead of translations:// ?
Comment #77
Gábor HojtsyThis exposed this pretty unfortunate side effect: #1787520: Translations not imported on installation - not necessarily a problem with this patch, rather how the module enable process works.
Comment #78
c960657 CreditAttribution: c960657 commentedFollow-up: #1791920: Create new translations:// directory for tests
Comment #80
effulgentsia CreditAttribution: effulgentsia commentedThis is causing a problem with the installer. See #1864292: Installation in non-English language fails.
Comment #80.0
effulgentsia CreditAttribution: effulgentsia commentedUpdate the summary, using the template summary template.