-
Notifications
You must be signed in to change notification settings - Fork 146
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
base: trunk
Are you sure you want to change the base?
Translate: Add additional custom errors #320
Conversation
return esc_html__( | ||
'Must be ' . $this->array_to_string( self::CONTEXT_ENUM_CHECK_LIST[$gp_original->context] ), | ||
'glotpress' | ||
); |
There was a problem hiding this comment.
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:
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 ) { |
There was a problem hiding this comment.
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
.
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' ], | ||
]; |
There was a problem hiding this comment.
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 option2Word: option1 or option2
= Must be option1 or option2Do 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.
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.