Skip to content

Commit

Permalink
657 automate localizations (#4003)
Browse files Browse the repository at this point in the history
* Adds i18n-tasks gem & associated tests

* Adds Gems & config necessary to connect i18n-tasks with openai

* Comments out test from i18n-tasks

* Removes two other gems for now to see if those are impacting build failures

* Drops i18n-tasks gem version to one that supports ruby 2.7

* Updates i18n-tasks gem back to latest release

* Removes redundant config file

* Restricts version of i18n-tasks dependency highline

* Results of running i18n-tasks normalize

* Updates to most recent version of i18n-tasks

* The results of running i18n-tasks add-missing

* Adds gems necessary to translate missing keys

* Removes gems that cause build failure
  • Loading branch information
HazelGrant authored Dec 19, 2024
1 parent 58a5ee9 commit ccfb597
Show file tree
Hide file tree
Showing 7 changed files with 920 additions and 407 deletions.
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'
# gem 'ruby-openai'
end

# lock gems to versions that are compatible with ruby 2.7.0,
Expand Down
24 changes: 24 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 @@ -115,11 +116,22 @@ GEM
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)
Expand Down Expand Up @@ -181,6 +193,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 +231,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.10.0)
psych (>= 4.0.0)
Expand Down Expand Up @@ -266,6 +285,8 @@ 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)
tilt (2.4.0)
timecop (0.9.10)
Expand All @@ -276,6 +297,7 @@ GEM
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.0)
webrick (1.9.1)
websocket (1.2.11)
websocket-driver (0.7.6)
Expand All @@ -302,6 +324,8 @@ DEPENDENCIES
dotenv-rails (~> 2.1)
dotiw
erubi
highline (= 2.1.0)
i18n-tasks
jbuilder (~> 2.0)
jsbundling-rails (~> 1.0)
local_time (~> 1.0.3)
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

0 comments on commit ccfb597

Please sign in to comment.