You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+73Lines changed: 73 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,6 +107,79 @@ Keys marked as deleted (i.e. still existing but deleted from the Lit UI) are *no
107
107
108
108
Deleted keys whose translations are encountered during import are restored automatically.
109
109
110
+
### Cloud translation services
111
+
112
+
Lit can use external translation services such as [Google Cloud Translation API](https://cloud.google.com/translate/) and [Yandex.Translate API](https://translate.yandex.com/developers) to tentatively translate localizations to a given language.
113
+
Currently, Google and Yandex translation providers are supported, but extending it to any other translation provider of your choice is as easy as subclassing `Lit::CloudTranslation::Providers::Base`; see classes in `lib/lit/cloud_translation/providers` for reference.
114
+
115
+
#### Usage
116
+
117
+
Configure your translation provider using one of routines described below. When a translation provider is configured, each localization in Lit web UI will have a "Translate using _Provider Name_" button next to it, which by default translates to the localization's language from the localization currently saved for the app's `I18n.default_locale`.
118
+
Next to the button, there is a dropdown that allows translating from the key's localization in a language different than the default one.
To use translation via Google, you need to obtain a [service account key](https://cloud.google.com/iam/docs/creating-managing-service-account-keys) containing all the credentials required by the API.
135
+
136
+
These credentials can be given in three ways:
137
+
* via a `.json` keyfile, the path to which should be stored in the `GOOGLE_TRANSLATE_API_KEYFILE` environment variable,
138
+
* programmatically, in the initializer - be sure to use secrets in all the sensitive fields so you don't expose private credentials in the code:
139
+
```
140
+
Lit::CloudTranslation.configure do |config|
141
+
config.keyfile_hash = {
142
+
'type' => 'service_account',
143
+
'project_id' => 'foo',
144
+
'private_key_id' => 'keyid',
145
+
... # see Google docs link above for reference
146
+
}
147
+
end
148
+
```
149
+
* directly via `GOOGLE_TRANSLATE_API_<element>` environment variables, where e.g. the `GOOGLE_TRANSLATE_API_PROJECT_ID` variable corresponds to the `project_id` element of a JSON keyfile. Typically, only the following variables are mandatory:
150
+
*`GOOGLE_TRANSLATE_API_PROJECT_ID`
151
+
*`GOOGLE_TRANSLATE_API_PRIVATE_KEY` (make sure that it contains correct line breaks and markers of the private key's begin and end)
To use Yandex translation, an [API key must be obtained](https://translate.yandex.com/developers/keys). Then, you can pass it to your application via the `YANDEX_TRANSLATE_API_KEY` environment variable.
164
+
165
+
The API key can also be set programmatically in your Lit initializer (again, be sure to use secrets if you choose to do so):
166
+
```
167
+
Lit::CloudTranslation.configure do |config|
168
+
config.api_key = 'the_api_key'
169
+
end
170
+
```
171
+
172
+
### 0.3 -> 1.0 upgrade guide
173
+
174
+
Also applies to upgrading from `0.4.pre.alpha` versions.
175
+
176
+
1. Specify `gem 'lit', '~> 1.0'` in your Gemfile and run `bundle update lit`.
177
+
2. Run Lit migrations - `rails db:migrate`.
178
+
*__Caution:__ One of the new migrations adds a unique index in `lit_localizations` on `(localization_key_id, locale_id)`, which may cause constraint violations in some cases. If you encounter such errors during running this migration - in this case you'll need to enter Rails console and remove duplicates manually. The following query might be helpful to determine duplicate locale/localization key ID pairs:
0 commit comments