pfaffman
(Jay Pfaffman)
15 Marzo, 2021 19:43
1
¿Por qué no puedo tener una serialización zero en 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:
¿Hay alguna razón para no usar PLURALIZATION_KEYS en lugar de ENGLISH_KEYS aquí?
!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
Parece que zero funciona correctamente en mi código (el cual está roto por al menos otra razón que mis pruebas no detectaron).
gerhard
(Gerhard Schlager)
16 Marzo, 2021 11:03
2
Funciona porque el código i18n tiene un caso especial para la clave zero. Puedes seguir usándola siempre que no tengas la intención de utilizar una plataforma de traducción como Transifex o Crowdin. A menos que algo haya cambiado, estas plataformas solo admiten claves definidas por Unicode, que son “one” y “other” para el inglés. Por lo tanto, traducir la clave “zero” no funcionará, ya que esas plataformas la ignoran al analizar los archivos de configuración del idioma inglés.
pfaffman
(Jay Pfaffman)
16 Marzo, 2021 12:21
3
Maldita sea. Me temo que tiene sentido.
Gracias por la explicación.