Skip to content
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

#224 Allow for setting custom ID to avoid translation clobbering #225

Merged
merged 3 commits into from
Sep 19, 2019

Conversation

asmecher
Copy link
Contributor

Adds a Translation::setId function, with support for the Xliff extractor to call it with the Unit ID.

This permits the library to better conform to xliff's uniqueness requirements (the same source text can be translated several times with different unit IDs) while still supporting PO's uniqueness requirements (the same source text cannot appear twice in the same context).

Note that this means XLIFF files converted to PO files may lose some translations that appear several times with the same source text. (This is necessary to avoid a regression of #48.)

Note that I did not modify e.g. the PO extractor to use setId, even though it supports round-tripping XLIFF unit IDs. These unit IDs can still be read out from the comments or using \Gettext\Genreators\Xliff::getUnitID. (This felt like the best design choice.)

Note the warnings in Translation::setId and Translations::find: Translations with custom IDs (e.g. XLIFF unit IDs) may not be found by the Translations::find function, as it searches using IDs generated by the Translation::generateId function.

@oscarotero, this may break Translation::find for XLIFF files that were previously generated by this library, as they will use a md5 sum for the unit ID.

@oscarotero
Copy link
Member

this may break Translation::find for XLIFF files that were previously generated by this library, as they will use a md5 sum for the unit ID.

Yes, I'd add the $translation->setId($unitId); optional. Something like:

$translations = Translations::fromXliffFile('translations.xliff', ['unitid_as_id' => true]);

And by default, set to false.

@asmecher
Copy link
Contributor Author

@oscarotero, thanks, I've added that option and adjusted the tests accordingly. 3384000

@oscarotero oscarotero merged commit 241899f into php-gettext:master Sep 19, 2019
@oscarotero
Copy link
Member

Thanks!

@asmecher
Copy link
Contributor Author

Many thanks for your sensible stewardship, @oscarotero!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants