Problem/Motivation
One of the new fancy features of D8 UX is that when you select a Drupal.de.po translation file in import translations, it automatically pre-selects German (de). This is not the case if the file is called de.po. As this is the default file name when exporting Gettext PO files, this should be supported.
Forking from https://drupal.org/comment/8680903#comment-8680903
Proposed resolution
Detect the language on langcode.po files, as it does with project.langcode.po files.
Remaining tasks
Review the attached patch.
User interface changes
The selected language changes when the file is selected.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#9 | 2240555-9.patch | 940 bytes | penyaskito |
Comments
Comment #1
penyaskitoAttached a patch, which modifies the regular expression so myproject.langcode.po and langcode.po are both supported.
Comment #2
penyaskitoComment #3
Gábor HojtsyI think the English is not very clear here. We support two use cases. Either the filename is fully the language code or the filename ends with a language code.
I'm also not sure '\w' and '-' would match all characters possible in a language code?
Maybe we want the pattern as '/(ˆ|\.)([ˆ\.]+)\.po/ that is the start of the string or a dot followed by non-dots followed by .po, where we would take the non-dots?
Comment #4
penyaskitoSome browsers (the modern ones) prepend c:\fakepath\ to the filename, see http://lists.w3.org/Archives/Public/public-whatwg-archive/2009Mar/0309.html
So we need a solution that matches:
Your proposed regexp doesn't match the Windows/Unix path ones.
Building from there I got to
/([^.|)*(\.|\\|/)*([^.]+)\.po$/
, but I think readability is worse. So I would stick with/(|\.)([\-\w]+)\.po/
. Agree?Comment #5
Gábor HojtsyI never used pipe with an empty component. Would (|a) match ba too? Because it is b followed by empty followed by a :)
Comment #6
penyaskitoNo, (|a) doesn't match ba. I don't really know why it works, but it does.
Maybe we should stick to /([^.|)*(\.|\\|/)*([^.]+)\.po$/, which is more complex to parse on your head but easier to understand?
Comment #7
Gábor Hojtsy([^.|)* seems to be not only hard to parse in head but also invalid? [ would need to be followed by ] at some point.
Comment #8
Gábor HojtsyFix tags.
Comment #9
penyaskitoNew attempt, using
/([^.][\.]*)([\w-]+)\.po$/
: whatever followed by a dot (or nothing), langcode, which can be words and hyphens (es, ca-ES, etc), and the .po extension.This has worked with all my tests, but I don't have ATM any browser which treats upload files as UNIX paths.
Comment #10
Gábor HojtsyLooks all good to me.
Comment #12
Gábor Hojtsy9: 2240555-9.patch queued for re-testing.
Comment #13
Gábor HojtsyTotally random fails.
Comment #14
catchGood one for behat... Committed/pushed to 8.x, thanks!
Comment #16
Gábor HojtsySuperb, thanks.