idea-php-typo3-plugin icon indicating copy to clipboard operation
idea-php-typo3-plugin copied to clipboard

Feature request: context-sensitive LLL extraction and creation

Open NamelessCoder opened this issue 7 years ago • 4 comments

I'm a lazy developer and I don't much enjoy editing XLF files, so the following is a feature request for automatically creating LLL references in an XLF file in the two following contexts:

  • When I'm in TCA or other, and I have a hardcoded label, I'd like to select/highlight this label and click "create in XLF" and automatically "move" it there and convert the value to an LLL:EXT: reference, and...
  • When I'm in Fluid I'd and I have a hardcoded string anywhere, I'd like to be able to select/highlight that string and click "create in XLF, replace with inline ViewHelper call", or "create in XLF, replace with tag ViewHelper call" or "create in XLF, replace with LLL:EXT: reference. The generated reference should, if it is a tag or inline ViewHelper, use the default property to output the value that was previously hardcoded.

When I then click any of these options, I would like the following to happen:

  1. The extension context is determined based on where the file I edit is located.
  2. The available XLF files are listed in a selector and the default is locallang.xlf. This should include files from all (userland) extensions so I can create labels in other exts.
  3. A default "label identifier" is generated based on ???? (file location? TCA parameter? Argument it is used as?) and I can edit the identifier.

Bonus boss fights:

  • Adding the label to every localised XLF file
  • Toggle when used from Fluid, to render the f:translate call with extensionName and short label name instead of full LLL:EXT: reference without extensionName argument. For the initial version I'd say LLL:EXT... is perfectly sane and safe.

Round one. Fight! :)

NamelessCoder avatar Dec 08 '17 14:12 NamelessCoder

Hey Claus - awesome feature request!

I've already sketched a lot of the LLL integration. Here's a few hurdles:

  • PHPStorm (nor IntelliJ) doesn't ship with xlf as XML dialect (major bummer, this means I cannot traverse those precious LLL files properly. Fix is a new plugin that I might depend on: https://github.com/cedricziel/idea-xliff )
  • context resolving: we all do template overlays all the time. like in every project - i haven't solved this problem yet, so I need to start slowly by proposing the whole LLL:EXT:foo/bar/baz.xlf string without any context sensitivity, but I can provide an import handler that sets the required arguments on surrounding syntax elements
  • unfortunately fluid is currently not supported. my last info is that the inline syntax is no real language in the sense of a syntax tree and i refuse to do string parsing :)

cedricziel avatar Dec 08 '17 14:12 cedricziel

BTW: There is a basic integration for translations in the works, but it's still a lot of work in https://github.com/cedricziel/idea-php-typo3-plugin/pull/83

cedricziel avatar Dec 08 '17 14:12 cedricziel

context resolving: we all do template overlays all the time. like in every project - i haven't solved this problem yet, so I need to start slowly by proposing the whole LLL:EXT:foo/bar/baz.xlf string without any context sensitivity

Yep, and making it possible to select the target file from all extensions should help a lot with that. If user has to select then no worries - maybe PHPStorm can remember the file you selected and pre-select that next time?

unfortunately fluid is currently not supported

I'm totally fine with an ultra-naive way that doesn't know that it's Fluid at all, and just stupidly does search-and-replace and doesn't try to suggest one or the other based on where the replacement happens (in argument, outside, in text node, inline, etc.). If the resulting syntax needs for example escaping, that's a very small sacrifice, having to add those manually.

NamelessCoder avatar Dec 08 '17 14:12 NamelessCoder

Maybe a little bit off Topic, and not the complete Answer: but there ist a PHP Storm plugin called TYPO3 XLIFF that i use for such Translator tasks .

actully only works for a Fluid Template :

Select hardcoded Text right Mouse -> select generate -> translation -> select XLF File .. Result ends in: fluid template is <f:translate key="transKey"/> and XLF File with the needed XML infos ..

if you do the same in a php file like TCA you will have there not the LLL:EXT:.. String but <f:translate key="transKey"/>

velletti avatar Jan 19 '18 09:01 velletti