From 443b854ec73b5572e1e77c7051d4378259796b3d Mon Sep 17 00:00:00 2001 From: HazelGrant Date: Tue, 10 Dec 2024 09:04:37 -0500 Subject: [PATCH] Adds Gems & config necessary to connect i18n-tasks with openai --- apps/dashboard/Gemfile | 2 + apps/dashboard/Gemfile.lock | 25 ++++ apps/dashboard/config/i18n-tasks.yml.erb | 181 +++++++++++++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 apps/dashboard/config/i18n-tasks.yml.erb diff --git a/apps/dashboard/Gemfile b/apps/dashboard/Gemfile index 83190f165..886716bc4 100644 --- a/apps/dashboard/Gemfile +++ b/apps/dashboard/Gemfile @@ -40,6 +40,8 @@ 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 'easy_translate' + gem 'ruby-openai' end # lock gems to versions that are compatible with ruby 2.7.0, diff --git a/apps/dashboard/Gemfile.lock b/apps/dashboard/Gemfile.lock index 71427aa0c..51f36ef85 100644 --- a/apps/dashboard/Gemfile.lock +++ b/apps/dashboard/Gemfile.lock @@ -111,8 +111,20 @@ 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.0.4) + multipart-post (~> 2) + faraday-net_http (3.4.0) + net-http (>= 0.5.0) ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) @@ -139,6 +151,7 @@ GEM activesupport (>= 5.0.0) jsbundling-rails (1.3.1) railties (>= 6.0.0) + json (2.9.0) local_time (1.0.3) coffee-rails logger (1.6.2) @@ -168,8 +181,11 @@ GEM mocha (2.7.0) 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 @@ -261,6 +277,10 @@ GEM rexml (3.3.9) 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) @@ -292,6 +312,8 @@ GEM 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) @@ -302,6 +324,7 @@ GEM 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) @@ -327,6 +350,7 @@ DEPENDENCIES dalli dotenv-rails (~> 2.1) dotiw + easy_translate erubi i18n-tasks jbuilder (~> 2.0) @@ -344,6 +368,7 @@ DEPENDENCIES redcarpet (~> 3.3) rest-client (~> 2.0) rss (~> 0.2) + ruby-openai sdoc selenium-webdriver (= 4.5.0) sinatra diff --git a/apps/dashboard/config/i18n-tasks.yml.erb b/apps/dashboard/config/i18n-tasks.yml.erb new file mode 100644 index 000000000..fe432c481 --- /dev/null +++ b/apps/dashboard/config/i18n-tasks.yml.erb @@ -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}']] %>