roots / sage

WordPress starter theme with Laravel Blade components and templates, Tailwind CSS, and a modern development workflow
https://roots.io/sage/
MIT License
12.72k stars 3.06k forks source link

`wp i18n make-pot`: Warnings #2335

Closed strarsis closed 2 years ago

strarsis commented 4 years ago

Description

wp i18n make-pot lists warnings when extracting strings from a sage 9 theme:

Warning: The string "Search Results for %s" contains placeholders but has no "translators:" comment to clarify their meaning. (app/controllers/app.php:26)
Warning: The string "Error locating <code>%s</code> for inclusion." contains placeholders but has no "translators:" comment to clarify their meaning. (resources/functions.php:59)

Steps to reproduce

  1. Create new theme based on sage 9.
  2. Use wp i18n make-pot to extract strings (e.g. as npm script).

Expected behavior: No warnings emitted from wp cli i18n.

Actual behavior: Warnings emitted from wp cli i18n

Reproduces how often: Always.

Versions

### 9.0.9: February 13th, 2019
plumthedev commented 3 years ago

You need to add description for your translated string. WP Codex is clarify in this case https://codex.wordpress.org/I18n_for_WordPress_Developers#Descriptions

For example if your code looks like:

use \App\Services\Validation\SizeRule;

$error = __(
    sprintf('Required minimum %d characters', SizeRule::MIN_CHARACTERS)
    'text-domain'
);

You need to add translator for this magic %d for easily translate in feature and keep context.

So my example code need looks like:

use \App\Services\Validation\SizeRule;

/* translators: minimum characters count  */
$error = __(
    sprintf('Required minimum %d characters', SizeRule::MIN_CHARACTERS)
    'text-domain'
);

TLDR: Just add WordPress i18n translate description - by this you can write a "personal" message to the translators, so that they know how to deal with the string.

strarsis commented 2 years ago

@Log1x: Should these warnings be ignored and those special comments added afterwards? Or these comments directly added (Sage 10 has the same issue) to the theme repository?

strarsis commented 2 years ago

PR for fixing those i18n warnings: https://github.com/roots/sage/pull/3039