Skip to content

Translate: Add additional custom errors#320

Open
markoheijnen wants to merge 1 commit intoWordPress:trunkfrom
markoheijnen:translate/add-additional-custom-errors
Open

Translate: Add additional custom errors#320
markoheijnen wants to merge 1 commit intoWordPress:trunkfrom
markoheijnen:translate/add-additional-custom-errors

Conversation

@markoheijnen
Copy link
Copy Markdown

I was talking with @Zodiac1978 and he created https://gist.github.com/Zodiac1978/1d1bd363d5ba7d1ea68e3ffe352008f1. Based on that I updated the plugin with additional checks.

I also updated is_core_project() so it works for the main project as well.

Comment on lines +232 to +235
return esc_html__(
'Must be ' . $this->array_to_string( self::CONTEXT_ENUM_CHECK_LIST[$gp_original->context] ),
'glotpress'
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a literal string, given it's being translated:

Suggested change
return esc_html__(
'Must be ' . $this->array_to_string( self::CONTEXT_ENUM_CHECK_LIST[$gp_original->context] ),
'glotpress'
);
return sptintnt(
esc_html__(
'Must be one of %s',
'glotpress'
),
$this->array_to_string( self::CONTEXT_ENUM_CHECK_LIST[$gp_original->context] )
);
return true;
}
if ( ! str_contains( $gp_original->context, 'timezone date format' ) ) {
if ( strpos( $gp_original->comment, 'https://www.php.net/manual/datetime.format.php' ) === false ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can keep using str_contains() as WordPress has a polyfill for it. Unless you want to do a case-insensitive check then this should be a stripos.

Comment on lines +23 to +30
const CONTEXT_ENUM_CHECK_LIST = [
'text direction' => [ 'ltr', 'rtl' ],
'Open Sans font: on or off' => [ 'on', 'off' ],
'Open Sans font: add new subset (greek, cyrillic, vietnamese)' => [ 'no-subset', 'greek', 'cyrillic', 'vietnamese' ],
'Word count type. Do not translate!' => [ 'characters_excluding_spaces', 'characters_including_spaces', 'words' ],
'decline months names: on or off' => [ 'on', 'off' ],
'Comment number declension: on or off' => [ 'on', 'off' ],
];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These in general follow a specific format, I wonder if we could add something more generic.

  • Word: ... (option1, option2) = must be option1 or option2
  • Word: option1 or option2 = Must be option1 or option2
  • Do not translate in the comment, and neither of the above = Triple check please?

Wouldn't cover 100% of cases, but would help with such strings in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants