-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: i18n #2026
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
feat: i18n #2026
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| raise ValueError(_("Parameter value error: The uploaded audio lacks file_id, and the audio upload fails.")) | ||
| return self.execute(**self.node_params_serializer.data, **self.flow_params_serializer.data, | ||
| app_document_list=app_document_list, app_image_list=app_image_list, | ||
| app_audio_list=app_audio_list, |
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.
The code provided is mostly clear and free of major issues. Here are a few minor points to consider:
-
In the error message, replace
"Uploaded image lacking file_id"with"Uploaded audio lacks file_id". -
As
raise ValueError()suggests an issue in parameter values during upload, it might be beneficial to log this warning as well within the method_runusing something like:
logger.warning("Missing 'file_id' in uploaded media.")Here's your refined version of the code snippet:
@@ -63,7 +63,7 @@ def _run(self):
app_audio_list[1:])
for audio in app_audio_list:
if 'file_id' not in audio:
- raise ValueError(_("Parameter value error: Uploaded image lacks file_id, and the audio upload fails."))
+ raise ValueError(_("Parameter value error: Uploaded audio lacks file_id, and the audio upload fails."))
logger.warning("Missing 'file_id' in uploaded media.") # Optional logging suggestion
return self.execute(**self.node_params_serializer.data, **self.flow_params_serializer.data,
app_document_list=app_document_list, app_image_list=app_image_list,
app_audio_list=app_audio_list,These changes will ensure consistency across parameter name usage, handle missing file_id, and provide additional debugging information through logging.
| message=_("The field only supports string|int|dict|array|float"), code=500) | ||
| ]) | ||
| source = serializers.CharField(required=True, error_messages=ErrMessage.char(_("source")), validators=[ | ||
| validators.RegexValidator(regex=re.compile("^custom|reference$"), |
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.
There are a few issues in the provided code:
-
The
codeparameter in the regular expression validator has two different values (500) and does not match the default HTTP status codes (e.g., 400, 404). Consider using valid HTTP status codes. -
The translation key used in the error messages is incorrect. Using
_("field")instead of"field"might lead to unexpected results when translations are applied. Use double quotes within the format string for consistency.
Here's the corrected version of the code with these changes:
@@ -25,7 +25,7 @@ class InputField(serializers.Serializer):
is_required = serializers.BooleanField(required=True, error_messages=ErrMessage.boolean("Is this field required"))
type = serializers.CharField(required=True, error_messages=ErrMessage.char("type"), validators=[
validators.RegexValidator(
regex=re.compile("^string|int|dict|array|float$"),
- message=_("The field only supports string|int|dict|array|float"), code=500
+ message="The field only supports string|int|dict|array|float", code=400
)
])
source = serializers.CharField(required=True, error_messages=ErrMessage.char("source"), validators=[
validators.RegexValidator(
regex=re.compile("^custom|reference$")This should resolve both identified issues in the code.
| error_messages=ErrMessage.float(_('similarity'))) | ||
| search_mode = serializers.CharField(required=True, validators=[ | ||
| validators.RegexValidator(regex=re.compile("^embedding|keywords|blend$"), | ||
| message=_("The type only supports register|reset_password"), code=500) |
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.
Here's an analysis of the provided DatasetSettingSerializer code:
Irregularity/Suggestions
-
Variable Name Change:
- The variable name from
similarityto_similarityis unnecessary and should be removed. Variable names should reflect their intended purpose clearly.
- The variable name from
-
Field Definition Errors:
- In the first similari field definition (
similarity = ...), there seems to be a duplication of validation codes.Replacesimilarity = serializers.FloatField(required=True, max_value=2, min_value=0, error_messages=ErrMessage.float(_("Reference segment number")),
_float(withfloat.
- In the first similari field definition (
-
Error Message Translation:
- Some translations are not fully specified:
reference_segment_number` blend$
- Some translations are not fully specified:
-
Regular Expression for Validation:
- The regex pattern might need adjustments based on the expected input values:
regex=re.compile("^embedding|keywords|blend$")
- The regex pattern might need adjustments based on the expected input values:
Optimizations and Corrections
-
Remove Duplicated Error Messages:
similarity = serializers.FloatField( required=True, max_value=2, min_value=0, error_messages={ "max_value": ErrMessage.float("Maximum value exceeded for similarity"), "min_value": ErrMessage.float("Minimum value not met for similarity"), }, )
-
Correctly Defined Regular Expression:
Ensure the correct characters are used in the regular expression if needed:validator_regex = re.compile(r"^(embedding|keywords|blend)$") search_mode = serializers.CharField( required=True, validators=[validators.RegexValidator(regex=validator_regex)], message=_("The type only supports embedding|keywords|blend", code=500), )
These changes ensure that the serializer functions correctly without unnecessary duplication or errors.
feat: i18n