pfaffman
(Jay Pfaffman)
3월 15, 2021, 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}:",
invalid_setting_link_format:
"The following keys contain malformed setting link markers.\nUse {{setting:setting_name}} or {{settings:name_one,name_two|Link label}} (lowercase snake_case names, no spaces around commas):",
}.merge(
BANNED_PHRASES
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를 사용하지 않는 이유가 있나요?
yield(current_key, value.to_s)
end
end
end
def validate_content(yaml)
each_translation(yaml) do |key, value|
@errors[:invalid_relative_links] << key if value.match?(%r{href\s*=\s*["']/[^/]|\]\(/[^/]}i)
@errors[:invalid_relative_image_sources] << key if value.match?(%r{src\s*=\s*["']/[^/]}i)
if value.match?(/{{(?!settings?:).+?}}/)
exempt = key.end_with?("_MF") || EXEMPTED_DOUBLE_CURLY_BRACKET_KEYS.include?(key)
@errors[:invalid_interpolation_key_format] << key unless exempt
end
if value
.enum_for(:scan, SETTING_LINK_START_REGEX)
.map { Regexp.last_match.begin(0) }
.any? { |start| !value[start..].match?(VALID_SETTING_LINK_AT_START_REGEX) }
@errors[:invalid_setting_link_format] << key
제 코드에서는 zero가 정상적으로 작동하는 것 같습니다(테스트에서 포착되지 않은 다른 이유로 인해 코드가 깨져 있긴 하지만).
gerhard
(Gerhard Schlager)
3월 16, 2021, 11:03오전
2
i18n 코드가 zero 키에 대해 특별한 처리를 하고 있기 때문에 동작합니다. Transifex나 Crowdin과 같은 번역 플랫폼을 사용할 계획이 없다면 계속 사용해도 됩니다. 변경 사항이 없다면, 이러한 플랫폼은 영문의 경우 유니코드에서 정의된 "one"과 “other” 키만 지원하므로, 영문 로케일 파일을 파싱할 때 “zero” 키를 무시합니다. 따라서 “zero” 키를 번역하는 것은 작동하지 않습니다.