pfaffman
(Jay Pfaffman)
2021 年 3 月 15 日午後 7:43
1
client.en.yml で zero シリアライゼーションが使用できないのはなぜですか?
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:
ここで ENGLISH_KEYS ではなく PLURALIZATION_KEYS を使用しない理由はあるのでしょうか?
!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
私のコードでは zero は問題なく動作しているようです(ただし、私のテストでは検出されなかった少なくとも別の理由でコードは壊れています)。
gerhard
(Gerhard Schlager)
2021 年 3 月 16 日午前 11:03
2
i18n コードに zero キーに対する特別な処理があるため、動作します。Transifex や Crowdin などの翻訳プラットフォームを使用する予定がなければ、引き続き zero キーを使用できます。状況が変わっていない限り、それらのプラットフォームは Unicode で定義されたキーのみをサポートしており、英語の場合は「one」と「other」のみです。そのため、「zero」キーを翻訳しても機能しません。これらのプラットフォームは英語のロケールファイルを解析する際に zero キーを無視するためです。