Skip to content

[2.1][Translator] Symfony translation process & gettext #4245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
goetas opened this issue May 10, 2012 · 18 comments
Closed

[2.1][Translator] Symfony translation process & gettext #4245

goetas opened this issue May 10, 2012 · 18 comments

Comments

@goetas
Copy link
Contributor

goetas commented May 10, 2012

I have a question about symfony translation process.

Currently it seems that symfony does not support POT files. I've added into my symfony fork a custom PotFileDumper.

There is some symfony design choices that i not understand:

Q1: Why Symfony\Component\Translation\Dumper\FileDumper always crate files as {path}.{locale}.{extension}? With POT files {locale} has not sense because POT file is not yet localized. (http://en.wikipedia.org/wiki/File:Gettext.svg)

Q2: All message extractors (Symfony\Component\Translation\Extractor\ExtractorInterface) uses a "prefix" to mark the untranslated string. This behaviour in a gettext environment (using tools like Virtaal or Pootle) is very boring, this because in gettext an untranslated string is an empty string (not a prefixed string). (http://www.gnu.org/software/gettext/manual/gettext.html#Untranslated-Entries)

Q3: As i can see inside TranslationUpdateCommand, translation can be extract only form "Bundle"/Resources/views directory. Also this is very boring because i can have a very large set of software components, and i will need to extract translations from them. ( php files that uses function with __('String to translate') syntax).

Q4: The translation:update command is intended to extract messages from source, or to update MessageCatalogue adding the untranslated strings?

@goetas
Copy link
Contributor Author

goetas commented May 10, 2012

here i have a similar issue about Q2 (michelsalib/BCCExtraToolsBundle#25)

@goetas
Copy link
Contributor Author

goetas commented May 10, 2012

Regarding Q4, i do not understand why should i extract translations from MO files and dump them inside a xlif file...

@clemens-tolboom
Copy link
Contributor

@goetas Hi, I'm puzzled about the POT file import/export too.

Q1: We can easily overload FileDumper::dump by PoFileDumper to make it dump to a Gettext file with all Contexts (Domains) and without a locale.

Q2: When we have metadata into the Translation component (See Gettext.php providing for header and context info in #4249) we can also empty the translations.

I'm in favour now to allow PoFile* to also process .pot files. Or do we have to extends these? I haven't study MoFile* classes. So changes are we need to refactor both into a GettextFile* then extend to MO, PO and POT?

Q3, Q4: I'm not sure I get this one. When Q1 and Q2 are solved then having a MessageCatalogue we can dump all into on file? (Note: I'm only aware of Symfony Translation Component developing for Drupal CMS)

Can you give me some (links to) command-line examples working in a Symfony only context. See my blog http://build2be.com/content/symfony-development to get the idea ;)

@ghost
Copy link

ghost commented May 20, 2012

Yes, POT files are simply extracted keys which can be used to create or update PO files, which can in turn be compiled to .MO files. It's completely base language agnostic. This certainly needs to be corrected. /cc @fabpot

@goetas
Copy link
Contributor Author

goetas commented May 23, 2012

@clemens-tolboom
Q1: i've donethe same
Q2: metadata can be a solution. metadata will also add more power to translation component. (with some non-symfony project i found very useful have line numbers and filenames that originated the translatable strings)

@goetas
Copy link
Contributor Author

goetas commented May 23, 2012

currently i've implemented a POT dumper like this https://gist.github.com/2773646

for a general solution, should be done something like this: remove prefix functionality form Symfony\Component\Translation\Extractor\ExtractorInterface and all untranslated strings should be extracted as empty strings (this should involve php templates extractor, twig extractor....)

@goetas
Copy link
Contributor Author

goetas commented May 23, 2012

@Drak +1 @fabpot

@clemens-tolboom
Copy link
Contributor

@goetas You should really checkout my pull request #4249 as that adds a Gettext class providing for ie Gettext header and context support.

You PotFileDumper look ok at first sight but:

  • dump should be in a common class as bot PoFileDumper and PotFileDumper dump the same
  • both Po and Pot share similar format (equal?)

What can I do with your Gist? It is now not testable, mergable, etc.

Why not start a symfony clone?

:-)

@goetas
Copy link
Contributor Author

goetas commented May 23, 2012

tomorrow i will try to merge it into my clone

@Lumbendil
Copy link

@goetas has this been discontinued?

@goetas
Copy link
Contributor Author

goetas commented Aug 10, 2012

unfortunately yes, it has been discontinued. currently i'm involved in a different project...

maybe this winter i will put hands on this project..

@Lumbendil
Copy link

If I get some time I'll try to tackle it then.

@michelsalib
Copy link

Hi, @goetas. I will answer for Q2 and thus close issue michelsalib/BCCExtraToolsBundle#25. The use prefix was implemented initially to solve one single use case in some of my project : "I want to find with a simple CTRL-F all untranslated strings". At the time we decided to solve it using prefix. Afterward, I made the command public in the ExtraToolsBundle and pushed it in the symfony core.
If it is that boring (which seems to be, considering all the complains I have about that), I am not opposed to its removal.

BTW, sorry for being so late on the topic. I will follow your next PR.

ondrejmirtes pushed a commit to ondrejmirtes/symfony that referenced this issue Nov 25, 2013
This PR was merged into the master branch.

Commits
-------

320fb6c [Translation] changed the MetadataAwareInterface method signatures
11ff433 [Translation] fixed CS in unit tests
c40db35 [Translation] removed some code that is not done anywhere else in Symfony
63719a0 [Translation] created a new interface to avoid breaking BC
23e9e65 [Translation] fixed name
5607732 [Translation] added Metadata to MessageCatalogue

Discussion
----------

[MessageCatalogue] Add Metadata to MessageCatalogue

rework of symfony#4399

For improving the Gettext tools (PO, MO File Loader/Dumper) we need at least storage for their meta data.

This patch allows for issues below to store and process ie Po Header, Po Header Pluralisation rule.

Open
- [[WIP]: Allow Drupal to use Translate component](symfony#4249)
- [[2.1][Translator] Symfony translation process & gettext](symfony#4245)

Closed:
- [[Translation] Po/MoFileLoader parse plurization rules](symfony#3023)

It has 1 TODO regarding addCatalogue: it now just override old values with new.
@jakzal
Copy link
Contributor

jakzal commented Dec 23, 2013

@goetas is this issue still valid given #2590 was merged?

@goetas
Copy link
Contributor Author

goetas commented Dec 23, 2013

Q1: has not been solved... but as suggested by @clemens-tolboom, it can be extended & overwritten...
Q2: not solved, prefix is still used and it can't be set to empty string
Q3: Symfony 2.3.x scans only ....Bundle.../Resources/views directory to discover new translations... How to discover non-file translations? (i've a some extractors thato looks inside database to discover translations, so i'm completely ignoring resource directory )
Q4: is still valid... (JMS Translation Bundle do it right)

At this moment i'm using JMS Translation Bundle that to things in a better way.
Q2: JMS does not need a prefix
Q3: JMS can look outside of Resources/views directory
Q4: JMS uses translation:extract command just for translation extraction

Real question:
Why not remove 'translation:update' command form FrameworkBundle?
FrameworkBundle should be responsible just of "translation reading", and should leave responsibility of extraction&writing to other bundles.

Translation component (especially FileDumper) should allow any file naming, so any other framework that wanna use this component can create own file naming scheme.

@clemens-tolboom
Copy link
Contributor

Q2 is maybe solved through #6349 which was a continuation of part of #4249

@carsonbot
Copy link

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@chalasr
Copy link
Member

chalasr commented Dec 20, 2020

Closing as this is super old, things have moved a lot meanwhile.
Feel free to reopen if you think some of the problems raised here are still not solved on the current codebase.
Thank you.

@chalasr chalasr closed this as completed Dec 20, 2020
@carsonbot carsonbot removed the Stalled label Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants