wearerequired / traduttore

🗼 A WordPress plugin to improve the I18N workflow for your own projects based on @GlotPress.
https://wearerequired.github.io/traduttore/
72 stars 12 forks source link

Allow to customize the status of the strings to Export #259

Closed pedro-mendonca closed 6 months ago

pedro-mendonca commented 12 months ago

Issue Overview

The language packs only export entries with 'status' => 'current'. https://github.com/wearerequired/traduttore/blob/master/inc/Export.php#L75

While testing the GlotPress with Variants, this status don't allow to export also the root fallback entries. This is solved by setting 'status' => 'current_or_untranslated'.

I know the Variants feature of GlotPress was reverted and is far from being stable/released, but still, would it be possible to add a hook to allow a custom entries filter? Eg.:

$entries = GP::$translation->for_export( $this->project->get_project(), $this->translation_set, [ 'status' => 'current' ] );
/**
 * Filters the status of the entries to export.
 *
 * @param string                       $export_status   The status of the entries to export. Default is 'current'.
 * @param \GP_Translation_Set          $translation_set Translation set the language pack is for.
 * @param \Required\Traduttore\Project $project         The project that was updated.
 */
$export_status= apply_filters( 'traduttore.export_status', 'current', $this->translation_set, $this->project );
$entries = GP::$translation->for_export( $this->project->get_project(), $this->translation_set, [ 'status' => $export_status ] );

To Reproduce Steps to reproduce the behavior:

  1. Install GlotPress 3.0.0.alpha-4 to include variants
  2. Add a project with two translation sets, root and variant.
  3. Translate all the root set, only translate a few strings of the variant
  4. Currently the Variant language pack only includes the translated on the variant.

Expected behavior When exporting a laguage pack of a Variant, both translated and untranslated should be exported, to allow the fallback to the root locale.