Repository navigation
Support English and Spanish in Coplan #352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #!/usr/bin/env ruby | ||
|
|
||
| require "psych" | ||
|
|
||
| class LocaleLint | ||
| def initialize(locales) | ||
| @locales = locales | ||
| @locations = {} | ||
| end | ||
|
|
||
| def check(file, namespace:) | ||
| locale = File.basename(file)[/\A.+\.([a-zA-Z0-9-]+)\.yml\z/, 1] | ||
| abort "#{file}: expected a <surface>.<locale>.yml catalog" unless locale | ||
| abort "#{file}: add #{locale} to the checked locales in config/i18n-tasks.yml" unless @locales.include?(locale) | ||
|
|
||
| # safe_load rejects tags and aliases. Walk the syntax tree as well, since | ||
| # the loaded hash has already discarded any duplicate YAML keys. | ||
| catalog = Psych.safe_load_file(file) | ||
| unless catalog.is_a?(Hash) && | ||
| catalog.keys == [ locale ] && catalog[locale].is_a?(Hash) && | ||
| catalog[locale].keys == [ namespace ] && catalog[locale][namespace].is_a?(Hash) | ||
| abort "#{file}: expected a catalog under #{locale}.#{namespace}" | ||
| end | ||
|
|
||
| document, extra = Psych.parse_stream(File.read(file), filename: file).children | ||
| abort "#{file}: expected one YAML document" if extra | ||
| check_node(document.root, catalog, file, []) | ||
| rescue Psych::Exception => error | ||
| abort "#{file}: #{error.message}" | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def check_node(node, value, file, path) | ||
| location = "#{file}:#{node.start_line + 1}" | ||
| key_path = path.join(".") | ||
| first_node, first_location = @locations[key_path] | ||
| if first_node && !(node.is_a?(Psych::Nodes::Mapping) && first_node == node.class) | ||
| abort "#{location}: #{key_path} is also defined at #{first_location}" | ||
| end | ||
| @locations[key_path] ||= [ node.class, location ] | ||
|
|
||
| if node.is_a?(Psych::Nodes::Mapping) && value.is_a?(Hash) && !value.empty? | ||
| sibling_keys = {} | ||
| node.children.each_slice(2) do |key, child| | ||
| key_location = "#{file}:#{key.start_line + 1}" | ||
| name = key.value if key.is_a?(Psych::Nodes::Scalar) | ||
| abort "#{key_location}: expected a simple string key" unless name&.match?(/\A[\w-]+\z/) && value.key?(name) | ||
| abort "#{key_location}: duplicate key #{(path + [ name ]).join('.')}" if sibling_keys[name] | ||
| sibling_keys[name] = true | ||
| check_node(child, value.fetch(name), file, path + [ name ]) | ||
| end | ||
| elsif node.is_a?(Psych::Nodes::Scalar) && value.is_a?(String) && !value.strip.empty? | ||
| if value.match?(/<\/?[a-z!][^>]*>/i) | ||
| abort "#{location}: #{key_path} must be plain text. Put markup in the view." | ||
| end | ||
| else | ||
| abort "#{location}: #{key_path} must be a nonempty string or mapping" | ||
| end | ||
| end | ||
| end | ||
|
|
||
| Dir.chdir(File.expand_path("..", __dir__)) do | ||
| config = Psych.safe_load_file("config/i18n-tasks.yml") | ||
| lint = LocaleLint.new(config.fetch("locales")) | ||
| { | ||
| "engine/config/locales" => "coplan", | ||
| "config/locales" => "coplan_demo" | ||
| }.each do |directory, namespace| | ||
| Dir.glob("#{directory}/**/*").select { |path| File.file?(path) }.each do |file| | ||
| lint.check(file, namespace: namespace) | ||
| end | ||
| end | ||
| exec "bundle", "exec", "i18n-tasks", "health" | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| base_locale: en | ||
| locales: [en, es] | ||
|
|
||
| data: | ||
| read: | ||
| - engine/config/locales/**/*.%{locale}.yml | ||
| - config/locales/**/*.%{locale}.yml | ||
| yaml: | ||
| write: | ||
| line_width: -1 | ||
|
|
||
| search: | ||
| paths: | ||
| - engine/app | ||
| - app | ||
| only: ["*.rb", "*.erb", "*.js"] | ||
| prism: ruby |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --- | ||
| en: | ||
| coplan_demo: | ||
| navigation: | ||
| settings: Settings | ||
| sign_out: Sign out | ||
| sign_in: | ||
| admin_role: " · Admin" | ||
| choose_demo_account: Choose an account to sign in. | ||
| default_owner: Default owner | ||
| demo_accounts: Demo accounts | ||
| demo_hint_html: Try the demo as %{email}. Open “Demo library” for presentations, architecture, and review examples. | ||
| email_address: Email address | ||
| example_warning: This example host uses email-only sign in. No password is required. | ||
| instructions: Sign in with your work email | ||
| required: Please sign in. | ||
| signed_in: Signed in as %{name}. | ||
| signed_out: Signed out. | ||
| submit: Sign In | ||
| submitting: Signing in… | ||
| title: Sign In — Coplan |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script is now the CI gate for the translation catalogs, but it has no automated tests.
spec/lib/local_ci_spec.rbreplaces it with a stub that exits 0, and the PR body says the reject rules were checked by hand. If a later edit stops one rule from rejecting bad catalogs, CI stays green. Add a spec that writes small fixture catalogs to a temp directory and runs the script. Assert a non-zero exit for each rule: missing key, missing plural form, mismatched placeholders, duplicate keys in one file and across files, HTML markup, unused key, and unknown Stimulus key. Also assert that a clean fixture passes.