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

Translate: Add additional custom errors #320

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

markoheijnen
Copy link

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
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
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
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants