pfaffman
(Jay Pfaffman)
Março 15, 2021, 7:43pm
1
Por que não posso ter uma serialização zero em 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:
Há algum motivo para não usar PLURALIZATION_KEYS em vez de ENGLISH_KEYS aqui?
!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
O zero parece funcionar bem no meu código (que está com defeito por pelo menos outro motivo não detectado pelos meus testes).
gerhard
(Gerhard Schlager)
Março 16, 2021, 11:03am
2
Isso funciona porque o código de i18n tem um caso especial para a chave zero. Você pode continuar usando-a desde que não tenha a intenção de usar uma plataforma de tradução como Transifex ou Crowdin. A menos que algo tenha mudado, elas suportam apenas chaves definidas pelo Unicode, que são “one” e “other” para o inglês. Portanto, traduzir a chave “zero” não funcionará, pois essas plataformas a ignoram ao analisar os arquivos de locale em inglês.
pfaffman
(Jay Pfaffman)
Março 16, 2021, 12:21pm
3
Droga. Tenho medo que isso faça sentido.
Obrigado pela explicação.