pfaffman
(Jay Pfaffman)
Mars 15, 2021, 7:43
1
Pourquoi ne puis-je pas avoir une sérialisation zero dans client.en.yml ?
class LocaleFileValidator
# Format: "banned phrase" => "recommendation"
BANNED_PHRASES = { "color scheme" => "color palette", "private message" => "personal message" }
ERROR_MESSAGES = {
invalid_relative_links:
"The following keys have relative links, but do not start with %{base_url} or %{base_path}:",
invalid_relative_image_sources:
"The following keys have relative image sources, but do not start with %{base_url} or %{base_path}:",
invalid_interpolation_key_format:
"The following keys use {{key}} instead of %{key} for interpolation keys:",
wrong_pluralization_keys:
"Pluralized strings must have only the sub-keys 'one' and 'other'.\nThe following keys have missing or additional keys:",
invalid_file_format:
"The file is not a valid YAML format or does not contain a valid locale structure.",
invalid_one_keys:
"The following keys contain the number 1 instead of the interpolation key %{count}:",
}.merge(
BANNED_PHRASES
.map do |banned, recommendation|
[
exit 1 if has_errors
end
end
class LocaleFileValidator
# Format: "banned phrase" => "recommendation"
BANNED_PHRASES = { "color scheme" => "color palette", "private message" => "personal message" }
ERROR_MESSAGES = {
invalid_relative_links:
"The following keys have relative links, but do not start with %{base_url} or %{base_path}:",
invalid_relative_image_sources:
"The following keys have relative image sources, but do not start with %{base_url} or %{base_path}:",
invalid_interpolation_key_format:
"The following keys use {{key}} instead of %{key} for interpolation keys:",
wrong_pluralization_keys:
"Pluralized strings must have only the sub-keys 'one' and 'other'.\nThe following keys have missing or additional keys:",
invalid_file_format:
"The file is not a valid YAML format or does not contain a valid locale structure.",
invalid_one_keys:
Y a-t-il une raison de ne pas utiliser PLURALIZATION_KEYS plutôt que ENGLISH_KEYS ici ?
!EXEMPTED_DOUBLE_CURLY_BRACKET_KEYS.include?(key)
@errors[:invalid_interpolation_key_format] << key
end
BANNED_PHRASES.keys.each do |banned|
@errors["banned_phrase_#{banned}"] << key if value.downcase.include?(banned.downcase)
end
end
end
def each_pluralization(hash, parent_key = "", &block)
hash.each do |key, value|
if Hash === value
current_key = parent_key.empty? ? key : "#{parent_key}.#{key}"
each_pluralization(value, current_key, &block)
elsif PLURALIZATION_KEYS.include? key
yield(parent_key, hash)
end
end
end
Le zero semble fonctionner correctement dans mon code (qui est cassé pour au moins une autre raison non détectée par mes tests).
gerhard
(Gerhard Schlager)
Mars 16, 2021, 11:03
2
Cela fonctionne parce que le code i18n prévoit un cas spécial pour la clé zero. Vous pouvez continuer à l’utiliser tant que vous n’avez pas l’intention d’utiliser une plateforme de traduction comme Transifex ou Crowdin. Sauf changement, ces plateformes ne prennent en charge que les clés définies par Unicode, à savoir « one » et « other » pour l’anglais. Ainsi, traduire la clé « zero » ne fonctionnera pas, car ces plateformes l’ignorent lors de l’analyse des fichiers de locale anglais.
pfaffman
(Jay Pfaffman)
Mars 16, 2021, 12:21
3
Zut. J’ai peur que cela ait du sens.
Merci pour l’explication.