Skip to content
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

657 automate localizations #4003

Merged
merged 13 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/dashboard/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
# gem 'web-console', '~> 2.0'
gem 'i18n-tasks'
gem 'highline', '2.1.0'
gem 'easy_translate'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'easy_translate' and 'ruby-openai' bring in gem incompatibilities with Ruby 2.7. However, running bundle exec i18n-tasks translate-missing (which requires these two gems) translates zero keys. Do we need this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

I think longer term we will. Maybe we just can't automatic updates this until we drop 2.7 support?

gem 'ruby-openai'
end

# lock gems to versions that are compatible with ruby 2.7.0,
Expand Down
49 changes: 49 additions & 0 deletions apps/dashboard/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
autoprefixer-rails (10.2.5.1)
execjs (> 0)
base64 (0.2.0)
Expand Down Expand Up @@ -110,21 +111,45 @@ GEM
dotiw (5.3.3)
activesupport
i18n
easy_translate (0.5.1)
thread
thread_safe
erubi (1.13.0)
event_stream_parser (1.0.0)
execjs (2.10.0)
faraday (2.12.2)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-multipart (1.1.0)
multipart-post (~> 2.0)
faraday-net_http (3.4.0)
net-http (>= 0.5.0)
ffi (1.16.3)
globalid (1.2.1)
activesupport (>= 6.1)
highline (2.1.0)
http-accept (1.7.0)
http-cookie (1.0.8)
domain_name (~> 0.5)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
i18n-tasks (1.0.14)
activesupport (>= 4.0.2)
ast (>= 2.1.0)
erubi
highline (>= 2.0.0)
i18n
parser (>= 3.2.2.1)
rails-i18n
rainbow (>= 2.2.2, < 4.0)
terminal-table (>= 1.5.1)
jbuilder (2.13.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jsbundling-rails (1.3.1)
railties (>= 6.0.0)
json (2.9.1)
local_time (1.0.3)
coffee-rails
logger (1.6.3)
Expand Down Expand Up @@ -154,8 +179,11 @@ GEM
mocha (2.7.1)
ruby2_keywords (>= 0.0.5)
multi_json (1.15.0)
multipart-post (2.4.1)
mustermann (3.0.3)
ruby2_keywords (~> 0.0.1)
net-http (0.6.0)
uri
net-imap (0.3.7)
date
net-protocol
Expand All @@ -181,6 +209,9 @@ GEM
ood_support (~> 0.0.2)
rexml (~> 3.2)
ood_support (0.0.5)
parser (3.3.6.0)
ast (~> 2.4.1)
racc
pry (0.15.0)
coderay (~> 1.1)
method_source (~> 1.0)
Expand Down Expand Up @@ -216,13 +247,17 @@ GEM
rails-html-sanitizer (1.6.2)
loofah (~> 2.21)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
rails-i18n (7.0.10)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
railties (7.0.8.5)
actionpack (= 7.0.8.5)
activesupport (= 7.0.8.5)
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.2.1)
rdoc (6.9.0)
psych (>= 4.0.0)
Expand All @@ -238,6 +273,10 @@ GEM
rexml (3.4.0)
rss (0.3.1)
rexml
ruby-openai (7.3.1)
event_stream_parser (>= 0.3.0, < 2.0.0)
faraday (>= 1)
faraday-multipart (>= 1)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sdoc (2.6.1)
Expand Down Expand Up @@ -266,7 +305,11 @@ GEM
activesupport (>= 6.1)
sprockets (>= 3.0.0)
stringio (3.1.2)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
thor (1.3.2)
thread (0.2.2)
thread_safe (0.3.6)
tilt (2.4.0)
timecop (0.9.10)
timeout (0.4.2)
Expand All @@ -276,6 +319,8 @@ GEM
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.0)
uri (1.0.2)
webrick (1.9.1)
websocket (1.2.11)
websocket-driver (0.7.6)
Expand All @@ -301,7 +346,10 @@ DEPENDENCIES
dalli
dotenv-rails (~> 2.1)
dotiw
easy_translate
erubi
highline (= 2.1.0)
i18n-tasks
jbuilder (~> 2.0)
jsbundling-rails (~> 1.0)
local_time (~> 1.0.3)
Expand All @@ -317,6 +365,7 @@ DEPENDENCIES
redcarpet (~> 3.3)
rest-client (~> 2.0)
rss (~> 0.2)
ruby-openai
sdoc
selenium-webdriver (= 4.5.0)
sinatra
Expand Down
181 changes: 181 additions & 0 deletions apps/dashboard/config/i18n-tasks.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# i18n-tasks finds and manages missing and unused translations: https://github.com/glebm/i18n-tasks

# The "main" locale.
base_locale: en
## All available locales are inferred from the data by default. Alternatively, specify them explicitly:
# locales: [es, fr]
## Reporting locale, default: en. Available: en, ru.
# internal_locale: en

# Read and write translations.
data:
## Translations are read from the file system. Supported format: YAML, JSON.
## Provide a custom adapter:
# adapter: I18n::Tasks::Data::FileSystem

# Locale files or `Dir.glob` patterns where translations are read from:
read:
## Default:
# - config/locales/%{locale}.yml
## More files:
# - config/locales/**/*.%{locale}.yml

# Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom:
# `i18n-tasks normalize -p` will force move the keys according to these rules
write:
## For example, write devise and simple form keys to their respective files:
# - ['{devise, simple_form}.*', 'config/locales/\1.%{locale}.yml']
## Catch-all default:
# - config/locales/%{locale}.yml

# External locale data (e.g. gems).
# This data is not considered unused and is never written to.
external:
## Example (replace %#= with %=):
# - "<%#= %x[bundle info vagrant --path].chomp %>/templates/locales/%{locale}.yml"

## Specify the router (see Readme for details). Valid values: conservative_router, pattern_router, isolating_router, or a custom class.
# router: conservative_router

yaml:
write:
# do not wrap lines at 80 characters
line_width: -1

## Pretty-print JSON:
# json:
# write:
# indent: ' '
# space: ' '
# object_nl: "\n"
# array_nl: "\n"

# Find translate calls
search:
## Paths or `Find.find` patterns to search in:
# paths:
# - app/

## Root directories for relative keys resolution.
# relative_roots:
# - app/controllers
# - app/helpers
# - app/mailers
# - app/presenters
# - app/views

## Directories where method names which should not be part of a relative key resolution.
# By default, if a relative translation is used inside a method, the name of the method will be considered part of the resolved key.
# Directories listed here will not consider the name of the method part of the resolved key
#
# relative_exclude_method_name_paths:
# -

## Files or `File.fnmatch` patterns to exclude from search. Some files are always excluded regardless of this setting:
## *.jpg *.jpeg *.png *.gif *.svg *.ico *.eot *.otf *.ttf *.woff *.woff2 *.pdf *.css *.sass *.scss *.less
## *.yml *.json *.zip *.tar.gz *.swf *.flv *.mp3 *.wav *.flac *.webm *.mp4 *.ogg *.opus *.webp *.map *.xlsx
exclude:
- app/assets/images
- app/assets/fonts
- app/assets/videos
- app/assets/builds

## Alternatively, the only files or `File.fnmatch patterns` to search in `paths`:
## If specified, this settings takes priority over `exclude`, but `exclude` still applies.
# only: ["*.rb", "*.html.slim"]

## If `strict` is `false`, guess usages such as t("categories.#{category}.title"). The default is `true`.
# strict: true

## Allows adding ast_matchers for finding translations using the AST-scanners
## The available matchers are:
## - RailsModelMatcher
## Matches ActiveRecord translations like
## User.human_attribute_name(:email) and User.model_name.human
## - DefaultI18nSubjectMatcher
## Matches ActionMailer's default_i18n_subject method
##
## To implement your own, please see `I18n::Tasks::Scanners::AstMatchers::BaseMatcher`.
# ast_matchers:
# - 'I18n::Tasks::Scanners::AstMatchers::RailsModelMatcher'
# - 'I18n::Tasks::Scanners::AstMatchers::DefaultI18nSubjectMatcher'

## Multiple scanners can be used. Their results are merged.
## The options specified above are passed down to each scanner. Per-scanner options can be specified as well.
## See this example of a custom scanner: https://github.com/glebm/i18n-tasks/wiki/A-custom-scanner-example

## Translation Services
# translation:
# # Google Translate
# # Get an API key and set billing info at https://code.google.com/apis/console to use Google Translate
# google_translate_api_key: "AbC-dEf5"
# # DeepL Pro Translate
# # Get an API key and subscription at https://www.deepl.com/pro to use DeepL Pro
# deepl_api_key: "48E92789-57A3-466A-9959-1A1A1A1A1A1A"
# # deepl_host: "https://api.deepl.com"
# # deepl_version: "v2"
# # deepl_glossary_ids:
# # - f28106eb-0e06-489e-82c6-8215d6f95089
# # - 2c6415be-1852-4f54-9e1b-d800463496b4
# # add additional options to the DeepL.translate call: https://www.deepl.com/docs-api/translate-text/translate-text/
# deepl_options:
# formality: prefer_less
# # OpenAI
# openai_api_key: "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# # openai_model: "gpt-3.5-turbo" # see https://platform.openai.com/docs/models
# # may contain `%{from}` and `%{to}`, which will be replaced by source and target locale codes, respectively (using `Kernel.format`)
# # openai_system_prompt: >-
# # You are a professional translator that translates content from the %{from} locale
# # to the %{to} locale in an i18n locale array.
# #
# # The array has a structured format and contains multiple strings. Your task is to translate
# # each of these strings and create a new array with the translated strings.
# #
# # HTML markups (enclosed in < and > characters) must not be changed under any circumstance.
# # Variables (starting with %%{ and ending with }) must not be changed under any circumstance.
# #
# # Keep in mind the context of all the strings for a more accurate translation.
translation:
backend: openai
openai_api_key: <%= ENV["OPENAI_API_KEY"] %>

## Do not consider these keys missing:
# ignore_missing:
# - 'errors.messages.{accepted,blank,invalid,too_short,too_long}'
# - '{devise,simple_form}.*'

## Consider these keys used:
# ignore_unused:
# - 'activerecord.attributes.*'
# - '{devise,kaminari,will_paginate}.*'
# - 'simple_form.{yes,no}'
# - 'simple_form.{placeholders,hints,labels}.*'
# - 'simple_form.{error_notification,required}.:'

## Exclude these keys from the `i18n-tasks eq-base' report:
# ignore_eq_base:
# all:
# - common.ok
# fr,es:
# - common.brand

## Exclude these keys from the `i18n-tasks check-consistent-interpolations` report:
# ignore_inconsistent_interpolations:
# - 'activerecord.attributes.*'

## Ignore these keys completely:
# ignore:
# - kaminari.*

## Sometimes, it isn't possible for i18n-tasks to match the key correctly,
## e.g. in case of a relative key defined in a helper method.
## In these cases you can use the built-in PatternMapper to map patterns to keys, e.g.:
#
# <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
# only: %w(*.html.haml *.html.slim),
# patterns: [['= title\b', '.page_title']] %>
#
# The PatternMapper can also match key literals via a special %{key} interpolation, e.g.:
#
# <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
# patterns: [['\bSpree\.t[( ]\s*%{key}', 'spree.%{key}']] %>
Loading
Loading