Code Monkey home page Code Monkey logo

ruby-lokalise-api's Introduction

Lokalise API v2 official Ruby interface

Gem CI Coverage Status Downloads total

Official opinionated Ruby interface for the Lokalise API that represents returned data as Ruby objects.

Looking for a Rails integration? Try the lokalise_rails gem. Also you can use a lokalise_manager gem which allows to exchange translation files between Lokalise and any Ruby script.

Quickstart

Install the gem by running:

$ gem install ruby-lokalise-api

Obtain an API token in your personal profile (API tokens section) and initialize the client:

require 'ruby_lokalise_api'

@client = RubyLokaliseApi.client 'YOUR_TOKEN_HERE'

Now the @client can be used to perform API requests:

project = @client.project '123.abc'
project.name

process = @client.upload_file project_id,
                              data: 'Base-64 encoded data... ZnI6DQogI...',
                              filename: 'my_file.yml',
                              lang_iso: 'en'

process.status

Alternatively instantiate your client with an OAuth2 token:

@client = RubyLokaliseApi.oauth2_client 'YOUR_OAUTH2_TOKEN_HERE'

Learn how to generate an OAuth2 token in the docs.

Usage

Detailed documentation can be found at lokalise.github.io/ruby-lokalise-api.

You can also check this repo containing some usage examples and this blog post with explanations.

License

This gem is licensed under the BSD 3 Clause license. Prior to version 4 the license type was MIT.

Copyright (c) Lokalise team and Ilya Krukowski

ruby-lokalise-api's People

Contributors

bodrovis avatar dependabot[bot] avatar keymastervn avatar nickustinov avatar snkashis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

snkashis

ruby-lokalise-api's Issues

Simplify CRUD methods for resources

Methods like .new and .create in the Resource namespace should receive only client, path, and params. The path should be constructed elsewhere (in the Client perhaps) and stored for later method chaining. This will allow to get rid of endpoint_ids, resource_id, object_key and enable to introduce chained instance methods (#update and #destroy).

Possible solution: the Client has a separate method to construct path based on all the ids and object_key. It calls endpoint method for the corresponding resource and passes all stuff there, returning only the URI string.

Crash with addressable 2.8.2

Describe the bug

When upgrading addressable gem to 2.8.2, the following snippet fails:

require 'ruby_lokalise_api'
client = RubyLokaliseApi.client("<my_api_token>")
client.download_files("<my_project_id>", { ... })

The error message is: NoMethodError: undefined method 'to_str' for :projects:Symbol cf this line.

Please note that it works fine with addressable 2.8.1, and it does not hit that line (template.rb#L900).

Workaround

Fix the version of addressable to 2.8.1:

# Gemfile
gem 'addressable', "=2.8.1"`

Your environment:

  • OS : Ubuntu 22.04.2 LTS
  • Ruby version : 3.2.1

Cannot create a new Key with a Translation

Describe the bug
When I try to use the create_keys endpoint to create Key with a Translation, it fails.

To Reproduce

    client = RubyLokaliseApi.client AppConfig.setting["lokalise"]["api_token"]
    project_id = AppConfig.setting["lokalise"]["project_id"]
    key_name = "a_key"
    en_translation = "a translation"

    params = [
      {
        key_name: key_name,
        platforms: %w[web],
        translations: [
          {
              "language_iso": "en",
              "translation": en_translation
          }
        ]
      }
    ]

    keys = client.create_keys project_id, params

Expected behavior
Method runs without errors and Key and Translation are created on Lokalise.

Actual Behaviour

Method raises an exception with message:

RubyLokaliseApi::Error::BadRequest (Translation has no `translation` parameter)

Your environment:

  • OS: MacOS
  • Ruby version: 3.3.0

Additional context

NoMethodError: undefined method `delete_prefix'

Describe the bug
When trying to add the project it throws an error

NoMethodError: undefined method `delete_prefix' for "/projects/{{Project ID}}/":String

Full Trace

irb(main):016:0> @lokalise_client.project {{Project ID}}
NoMethodError: undefined method `delete_prefix' for "/projects/{{Project ID}}/":String
	from /Users/macbook/.rbenv/versions/2.4.9/lib/ruby/gems/2.4.0/gems/ruby-lokalise-api-3.1.0/lib/ruby-lokalise-api/request.rb:55:in `prepare'
	from /Users/macbook/.rbenv/versions/2.4.9/lib/ruby/gems/2.4.0/gems/ruby-lokalise-api-3.1.0/lib/ruby-lokalise-api/request.rb:13:in `get'
	from /Users/macbook/.rbenv/versions/2.4.9/lib/ruby/gems/2.4.0/gems/ruby-lokalise-api-3.1.0/lib/ruby-lokalise-api/resources/base.rb:67:in `find'
	from /Users/macbook/.rbenv/versions/2.4.9/lib/ruby/gems/2.4.0/gems/ruby-lokalise-api-3.1.0/lib/ruby-lokalise-api/client.rb:47:in `construct_request'
	from /Users/macbook/.rbenv/versions/2.4.9/lib/ruby/gems/2.4.0/gems/ruby-lokalise-api-3.1.0/lib/ruby-lokalise-api/rest/projects.rb:20:in `project'
	from (irb):16
	from /Users/macbook/.rbenv/versions/2.4.9/lib/ruby/gems/2.4.0/gems/railties-4.2.11.3/lib/rails/commands/console.rb:110:in `start'
	from /Users/macbook/.rbenv/versions/2.4.9/lib/ruby/gems/2.4.0/gems/railties-4.2.11.3/lib/rails/commands/console.rb:9:in `start'
	from /Users/macbook/.rbenv/versions/2.4.9/lib/ruby/gems/2.4.0/gems/railties-4.2.11.3/lib/rails/commands/commands_tasks.rb:68:in `console'
	from /Users/macbook/.rbenv/versions/2.4.9/lib/ruby/gems/2.4.0/gems/railties-4.2.11.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
	from /Users/macbook/.rbenv/versions/2.4.9/lib/ruby/gems/2.4.0/gems/railties-4.2.11.3/lib/rails/commands.rb:17:in `<top (required)>'
	from bin/rails:4:in `require'
	from bin/rails:4:in `<main>'

FYI: {{Project ID}} is my Lokalize project ID

Your environment:

  • OS (MacOS BigSur 11.3)
  • Ruby version (2.4.9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.