Skip to content

Commit

Permalink
Add rake task to fill missed locales
Browse files Browse the repository at this point in the history
  • Loading branch information
nbulaj committed Sep 24, 2021
1 parent 2e809c4 commit c0d5788
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
34 changes: 34 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require "bundler"
require "rake"
require "rspec/core"
require "rspec/core/rake_task"
require "yaml"

begin
Bundler.setup(:default, :development)
Expand All @@ -15,4 +16,37 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList["spec/**/*_spec.rb"]
end

def en_locale
@en_locale ||= YAML.load_file(File.join("rails", "locales", "en.yml"))
end

def merge_locales(source, target)
source.inject({}) do |locale, (key, value)|
if value.is_a?(Hash)
locale[key] = merge_locales(value, target[key] || {})
else
locale[key] = target[key].nil? ? source[key] : target[key]
end

locale
end
end

task default: :spec

task :fill do
Dir.glob(File.join("rails", "locales", "*.yml")).each do |file|
next if File.basename(file) == "en.yml"

puts "Processing #{File.basename(file)}"

locale = YAML.load_file(file)
lang = locale.keys.first.dup

merged_locale = merge_locales(en_locale.fetch("en"), locale.fetch(lang))

File.open(file, "w") do |f|
f.write(YAML.dump({ lang => merged_locale }, line_width: -1).gsub("---\n", ''))
end
end
end
23 changes: 6 additions & 17 deletions rails/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ en:
doorkeeper/application:
name: 'Name'
redirect_uri: 'Redirect URI'
scopes: 'Scopes'
errors:
models:
doorkeeper/application:
Expand All @@ -18,7 +17,6 @@ en:
forbidden_uri: 'is forbidden by the server.'
scopes:
not_match_configured: "doesn't match configured on the server."

doorkeeper:
applications:
confirmations:
Expand Down Expand Up @@ -52,13 +50,14 @@ en:
title: 'New Application'
show:
title: 'Application: %{name}'
application_id: 'Application UID'
application_id: 'UID'
secret: 'Secret'
secret_hashed: 'Secret hashed'
scopes: 'Scopes'
confidential: 'Confidential'
callback_urls: 'Callback urls'
actions: 'Actions'

not_defined: 'Not defined'
authorizations:
buttons:
authorize: 'Authorize'
Expand All @@ -71,7 +70,8 @@ en:
able_to: 'This application will be able to'
show:
title: 'Authorization code'

form_post:
title: 'Submit this form'
authorized_applications:
confirmations:
revoke: 'Are you sure?'
Expand All @@ -82,13 +82,10 @@ en:
application: 'Application'
created_at: 'Created At'
date_format: '%Y-%m-%d %H:%M:%S'

pre_authorization:
status: 'Pre-authorization'

errors:
messages:
# Common error messages
invalid_request:
unknown: 'The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.'
missing_param: 'Missing required parameter: %{value}.'
Expand All @@ -100,20 +97,14 @@ en:
invalid_code_challenge_method: 'The code challenge method must be plain or S256.'
server_error: 'The authorization server encountered an unexpected condition which prevented it from fulfilling the request.'
temporarily_unavailable: 'The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.'

# Configuration error messages
credential_flow_not_configured: 'Resource Owner Password Credentials flow failed due to Doorkeeper.configure.resource_owner_from_credentials being unconfigured.'
resource_owner_authenticator_not_configured: 'Resource Owner find failed due to Doorkeeper.configure.resource_owner_authenticator being unconfigured.'
admin_authenticator_not_configured: 'Access to admin panel is forbidden due to Doorkeeper.configure.admin_authenticator being unconfigured.'

# Access grant errors
unsupported_response_type: 'The authorization server does not support this response type.'

# Access token errors
unsupported_response_mode: 'The authorization server does not support this response mode.'
invalid_client: 'Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method.'
invalid_grant: 'The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.'
unsupported_grant_type: 'The authorization grant type is not supported by the authorization server.'

invalid_token:
revoked: "The access token was revoked"
expired: "The access token expired"
Expand All @@ -122,7 +113,6 @@ en:
unauthorized: "You are not authorized to revoke this token"
forbidden_token:
missing_scope: 'Access to this resource requires scope "%{oauth_scopes}".'

flash:
applications:
create:
Expand All @@ -134,7 +124,6 @@ en:
authorized_applications:
destroy:
notice: 'Application revoked.'

layouts:
admin:
title: 'Doorkeeper'
Expand Down

0 comments on commit c0d5788

Please sign in to comment.