Skip to content

Commit 65e987b

Browse files
committed
bump\
1 parent 267451d commit 65e987b

4 files changed

Lines changed: 76 additions & 76 deletions

File tree

README.md

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,76 @@ To export translations from your Rails app to the specified Lokalise project, ru
6969
rails lokalise_rails:export
7070
```
7171

72+
## Configuration
73+
74+
Options are specified in the `config/lokalise_rails.rb` file.
75+
76+
Here's an example:
77+
78+
```ruby
79+
LokaliseRails::GlobalConfig.config do |c|
80+
# These are mandatory options that you must set before running rake tasks:
81+
c.api_token = ENV['LOKALISE_API_TOKEN']
82+
c.project_id = ENV['LOKALISE_PROJECT_ID']
83+
84+
# Provide a custom path to the directory with your translation files:
85+
# c.locales_path = "#{Rails.root}/config/locales"
86+
87+
# Provide a Lokalise project branch to use:
88+
c.branch = 'develop'
89+
90+
# Provide request timeouts for the Lokalise API client:
91+
c.additional_client_opts = {open_timeout: 5, timeout: 5}
92+
93+
# Provide maximum number of retries for file exporting:
94+
c.max_retries_export = 5
95+
96+
# Provide maximum number of retries for file importing:
97+
c.max_retries_import = 5
98+
99+
# Import options have the following defaults:
100+
# c.import_opts = {
101+
# format: 'ruby_yaml',
102+
# placeholder_format: :icu,
103+
# yaml_include_root: true,
104+
# original_filenames: true,
105+
# directory_prefix: '',
106+
# indentation: '2sp'
107+
# }
108+
109+
# Safe mode for imports is disabled by default:
110+
# c.import_safe_mode = false
111+
112+
# Additional export options (only filename, contents, and lang_iso params are provided by default)
113+
# c.export_opts = {}
114+
115+
# Provide additional file exclusion criteria for exports (by default, any file with the proper extension will be exported)
116+
# c.skip_file_export = ->(file) { file.split[1].to_s.include?('fr') }
117+
118+
# Set the options below if you would like to work with format other than YAML
119+
## Regular expression to use when choosing the files to extract from the downloaded archive and upload to Lokalise
120+
## c.file_ext_regexp = /\.ya?ml\z/i
121+
122+
## Load translations data and make sure they are valid:
123+
## c.translations_loader = ->(raw_data) { YAML.safe_load raw_data }
124+
125+
## Convert translations data to a proper format:
126+
## c.translations_converter = ->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') }
127+
128+
## Infer language ISO code for the translation file:
129+
## c.lang_iso_inferer = ->(data, _path) { YAML.safe_load(data)&.keys&.first }
130+
131+
## Pre-process translations before exporting to Lokalise:
132+
## c.export_preprocessor = ->(raw_data, _path) { raw_data }
133+
134+
## Disable the export rake task:
135+
## c.disable_export_task = false
136+
137+
## Disable the import rake task:
138+
## c.disable_import_task = false
139+
end
140+
```
141+
72142
## Running tasks programmatically
73143

74144
You can also run the import and export tasks programmatically from your code. To achieve that, please check the [`lokalise_manager`](https://github.com/bodrovis/lokalise_manager) gem which `lokalise_rails` relies on.
@@ -217,76 +287,6 @@ end
217287

218288
Named projects are configured with `for_project(:name)` and generate scoped tasks like `lokalise_rails:<name>:import` and `lokalise_rails:<name>:export`.
219289

220-
## Configuration
221-
222-
Options are specified in the `config/lokalise_rails.rb` file.
223-
224-
Here's an example:
225-
226-
```ruby
227-
LokaliseRails::GlobalConfig.config do |c|
228-
# These are mandatory options that you must set before running rake tasks:
229-
c.api_token = ENV['LOKALISE_API_TOKEN']
230-
c.project_id = ENV['LOKALISE_PROJECT_ID']
231-
232-
# Provide a custom path to the directory with your translation files:
233-
# c.locales_path = "#{Rails.root}/config/locales"
234-
235-
# Provide a Lokalise project branch to use:
236-
c.branch = 'develop'
237-
238-
# Provide request timeouts for the Lokalise API client:
239-
c.additional_client_opts = {open_timeout: 5, timeout: 5}
240-
241-
# Provide maximum number of retries for file exporting:
242-
c.max_retries_export = 5
243-
244-
# Provide maximum number of retries for file importing:
245-
c.max_retries_import = 5
246-
247-
# Import options have the following defaults:
248-
# c.import_opts = {
249-
# format: 'ruby_yaml',
250-
# placeholder_format: :icu,
251-
# yaml_include_root: true,
252-
# original_filenames: true,
253-
# directory_prefix: '',
254-
# indentation: '2sp'
255-
# }
256-
257-
# Safe mode for imports is disabled by default:
258-
# c.import_safe_mode = false
259-
260-
# Additional export options (only filename, contents, and lang_iso params are provided by default)
261-
# c.export_opts = {}
262-
263-
# Provide additional file exclusion criteria for exports (by default, any file with the proper extension will be exported)
264-
# c.skip_file_export = ->(file) { file.split[1].to_s.include?('fr') }
265-
266-
# Set the options below if you would like to work with format other than YAML
267-
## Regular expression to use when choosing the files to extract from the downloaded archive and upload to Lokalise
268-
## c.file_ext_regexp = /\.ya?ml\z/i
269-
270-
## Load translations data and make sure they are valid:
271-
## c.translations_loader = ->(raw_data) { YAML.safe_load raw_data }
272-
273-
## Convert translations data to a proper format:
274-
## c.translations_converter = ->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') }
275-
276-
## Infer language ISO code for the translation file:
277-
## c.lang_iso_inferer = ->(data, _path) { YAML.safe_load(data)&.keys&.first }
278-
279-
## Pre-process translations before exporting to Lokalise:
280-
## c.export_preprocessor = ->(raw_data, _path) { raw_data }
281-
282-
## Disable the export rake task:
283-
## c.disable_export_task = false
284-
285-
## Disable the import rake task:
286-
## c.disable_import_task = false
287-
end
288-
```
289-
290290
## Running tests
291291

292292
1. Copy-paste `.env.example` file as `.env`. Put your Lokalise API token and project ID inside. The `.env` file is excluded from version control so your data is safe. All in all, we use stubbed requests, so the actual API requests won't be sent. However, providing at least some values is required.

gemfiles/Gemfile-rails-6-1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ group :test do
1515
gem 'tzinfo-data', platforms: tz_platforms
1616
gem 'dotenv', '~> 2.5'
1717
gem 'mutex_m', '~> 0.3.0'
18-
gem 'rails', '~> 6.1'
18+
gem 'rails', '6.1.7.10'
1919
gem 'webmock', '~> 3.14'
2020
end

gemfiles/Gemfile-rails-7-1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ tz_platforms =
1414
group :test do
1515
gem 'tzinfo-data', platforms: tz_platforms
1616
gem 'dotenv', '~> 3.0'
17-
gem 'rails', '~> 7.1', '< 7.2'
17+
gem 'rails', '7.1.6'
1818
gem 'webmock', '~> 3.14'
1919
end
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# frozen_string_literal: true
22

3-
if defined?(LokaliseRails::GlobalConfig)
3+
if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig)
44
LokaliseRails::GlobalConfig.config do |c|
5-
c.api_token = ENV.fetch('LOKALISE_API_TOKEN', nil)
6-
c.project_id = ENV.fetch('LOKALISE_PROJECT_ID', nil)
5+
c.api_token = ENV["LOKALISE_API_TOKEN"]
6+
c.project_id = ENV["LOKALISE_PROJECT_ID"]
77
end
88

99
LokaliseRails::GlobalConfig.for_project(:dummy_project) do |c|
10-
c.project_id = ENV.fetch('LOKALISE_PROJECT_ID', nil)
10+
c.project_id = ENV["LOKALISE_PROJECT_ID"]
1111
end
1212
end

0 commit comments

Comments
 (0)