php-gettext / Gettext

PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)
MIT License
687 stars 132 forks source link

Follow GNU .po files headers formatting #251

Closed NathanBnm closed 4 years ago

NathanBnm commented 4 years ago

Is there a way to follow the recommended gnu headers for .po files as following? With the copyright header and description.

# SOME DESCRIPTIVE TITLE
# Copyright (C) YEAR Free Software Foundation, Inc.
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2008-02-06 16:25-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: ENCODING\n"
oscarotero commented 4 years ago

I think there's no way to insert this comment before the headers right now. But it's easy to implement. I imagine something like this:

$translations->setDescription(<<<EOT
SOME DESCRIPTIVE TITLE
Copyright (C) YEAR Free Software Foundation, Inc.
This file is distributed under the same license as the PACKAGE package.
FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
EOT);

I don't know whether adding flags to the headers makes sense (fuzzy).

NathanBnm commented 4 years ago

Sure it could be a great feature :smile:

I don't know whether adding flags to the headers makes sense (fuzzy).

It makes sense because it's used to notice the translators that one or more translations in the file are fuzzy, without having to scroll down all the file.

oscarotero commented 4 years ago

Ok, where did you see this example?

NathanBnm commented 4 years ago

You can see specifications here: https://www.gnu.org/software/trans-coord/manual/gnun/html_node/PO-Header.html

For further info: https://www.gnu.org/software/gettext/manual/html_node/index.html

Some of these specifications could be adapted or removed to fit better with your scripts. But I think the comments before the header, the "Po-Revision-Date" and the "Content-Type" are useful to implement. Setting the "Last-Translator" field could be great too. By default it should be "Automatically generated" (same for "FIRST AUTHOR" in comments before the header).

oscarotero commented 4 years ago

New version released including these features:

$translations->setDescription($description);
$translations->getFlags()->add('fuzzy');
NathanBnm commented 4 years ago

@oscarotero is there a possibility to add the fuzzy flag automatically? I mean when a translation has been changed, it is erased from the PO file. The issue is that sometimes it's just a little difference like a colon or a single word. It would be great not to erase completly the concerning translation but mark it as fuzzy when there are a few changes to the string.

oscarotero commented 4 years ago

I don't understand. Do you mean the Translations class handles the flags automatically according to the flags added in each translation? This class should contain the less logic (aka magic) possible, so anyone can edit the content, add or remove flags according to his own standards.

NathanBnm commented 4 years ago

Yes but it would be an option, maybe a new Merge method.

oscarotero commented 4 years ago

Currently, the translations flags are using the same option as the individual translation (https://github.com/php-gettext/Gettext/blob/master/src/Translations.php#L188)