README.md in lokalise_manager-2.1.0 vs README.md in lokalise_manager-2.2.0

- old
+ new

@@ -41,11 +41,11 @@ # OR exporter = LokaliseManager.exporter api_token: '1234abc', project_id: '123.abc' ``` -You *must* provide an API token and a project ID (your project ID can be found under Lokalise project settings). [Other options can be customized as well (see below)](https://github.com/bodrovis/lokalise_manager#configuration) but they have sensible defaults. +You *must* provide an API token and a project ID (your project ID can be found under Lokalise project settings). [Other options can be customized as well (see below)](#configuration) but they have sensible defaults. ### Importing files from Lokalise into your project To download translation files from Lokalise into your project (by default all files will be stored under the `locales/` directory), run the following code: @@ -53,33 +53,35 @@ result = importer.import! ``` The `result` will contain a boolean value which says whether the operation was successfull or not. -Please note that upon importing translations any duplicating files inside the `locales` directory (or any other directory that you've specified in the options) will be overwritten! You can enable [safe mode](https://github.com/bodrovis/lokalise_manager#import-config) to check whether the folder is empty or not. +Please note that upon importing translations any duplicating files inside the `locales` directory (or any other directory that you've specified in the options) **will be overwritten**! You can enable [safe mode](#import-config) to check whether the folder is empty or not. ### Exporting files from your project to Lokalise To upload your translation files from a local directory (defaults to `locales/`) to a Lokalise project, run the following code: ```ruby processes = exporter.export! ``` +The uploading process is multi-threaded. + `processes` will contain an array of objects responding to the following methods: -* `success` — usually returns `true` (to learn more, check documentation for the `:raise_on_export_fail` option below) -* `process` — returns an object (an instance of the `Lokalise::Resources::QueuedProcess`) representing a [queued background process](https://lokalise.github.io/ruby-lokalise-api/api/queued-processes) as uploading is done in the background on Lokalise. -* `path` — returns an instance of the `Pathname` class which represent the file being uploaded. +* `#success` — usually returns `true` (to learn more, check documentation for the `:raise_on_export_fail` option below) +* `#process` — returns an object (an instance of the `Lokalise::Resources::QueuedProcess`) representing a [queued background process](https://lokalise.github.io/ruby-lokalise-api/api/queued-processes) as uploading is done in the background on Lokalise. +* `#path` — returns an instance of the `Pathname` class which represent the file being uploaded. You can perform periodic checks to read the status of the process. Here's a very simple example: ```ruby def uploaded?(process) 5.times do # try to check the status 5 times - process = process.reload_data # load new data - return(true) if process.status == 'finished' # return true is the upload has finished + process = process.reload_data # load new info about this process + return(true) if process.status == 'finished' # return true if the upload has finished sleep 1 # wait for 1 second, adjust this number with regards to the upload size end false # if all 5 checks failed, return false (probably something is wrong) end @@ -167,11 +169,11 @@ ```ruby c.skip_file_export = ->(file) { f.split[1].to_s.include?('fr') } ``` -* `max_retries_export` (`integer`) — this option is introduced to properly handle Lokalise API rate limiting. If the HTTP status code 429 (too many requests) has been received, LokaliseRails will apply an exponential backoff mechanism with a very simple formula: `2 ** retries` (initially `retries` is `0`). If the maximum number of retries has been reached, a `Lokalise::Error::TooManyRequests` exception will be raised and the export operation will be halted. By default, LokaliseManager will make up to `5` retries which potentially means `1 + 2 + 4 + 8 + 16 + 32 = 63` seconds of waiting time. If the `max_retries_export` is less than `1`, LokaliseRails will not perform any retries and give up immediately after receiving error 429. +* `max_retries_export` (`integer`) — this option is introduced to properly handle Lokalise API rate limiting. If the HTTP status code 429 (too many requests) has been received, LokaliseManager will apply an exponential backoff mechanism with a very simple formula: `2 ** retries` (initially `retries` is `0`). If the maximum number of retries has been reached, a `Lokalise::Error::TooManyRequests` exception will be raised and the export operation will be halted. By default, LokaliseManager will make up to `5` retries which potentially means `1 + 2 + 4 + 8 + 16 + 32 = 63` seconds of waiting time. If the `max_retries_export` is less than `1`, LokaliseManager will not perform any retries and give up immediately after receiving error 429. * `raise_on_export_fail` (`boolean`) — default is `true`. When this option is enabled, LokaliseManager will re-raise any exceptions that happened during the file uploading. In other words, if any uploading thread raised an exception, your exporting process will exit with an exception. Suppose, you are uploading 12 translation files; these files will be split in 2 groups with 6 files each, and each group will be uploaded in parallel (using threads). However, suppose some exception happens when uploading the first group. By default this exception will be re-raised for the whole process and the script will never try to upload the second group. If you would like to continue uploading even if an exception happened, set the `raise_on_export_fail` to `false`. In this case the `export!` method will return an array with scheduled processes and with information about processes that were not successfully scheduled. This information is represented as an object with three methods: `path` (contains an instance of the `Pathname` class which says which file could not be uploaded), `error` (the actual exception), and `success` (returns `false`). So, you can use the following snippet to check your processes: ```ruby processes = exporter.export! @@ -220,10 +222,10 @@ translations_converter: -> (raw_data) { raw_data } ``` These options will be merged with the default ones. Please note that per-client config has the highest priority. -You can also adjust individual options later using the `#config` instance variable (it contains an OpenStruct object): +You can also adjust individual options later using the `#config` instance variable (it contains a Struct object): ``` importer.config.project_id = '678xyz' importer.config.branch = 'develop' ```