Code Monkey home page Code Monkey logo

Comments (10)

bodrovis avatar bodrovis commented on July 26, 2024 1

Here's a full example with a custom Rake task that uploads translations to Lokalise from two different paths:

require 'rake'
require 'lokalise_rails'
require "#{LokaliseRails::Utils.root}/config/lokalise_rails"

namespace :lokalise_custom do
  task :export do
    # importing from the default directory (./config/locales/)
    exporter = LokaliseManager.exporter({}, LokaliseRails::GlobalConfig)
    exporter.export!

    # importing from the custom directory
    exporter = LokaliseManager.exporter({locales_path: "#{Rails.root}/config/custom_locales"}, LokaliseRails::GlobalConfig)
    exporter.export!
  rescue StandardError => e
    abort e.inspect
  end
end

from lokalise_rails.

bodrovis avatar bodrovis commented on July 26, 2024

Good day! Please post full contents of your Gemfile. It seems like you're specifying conflicting versions for the gems. Also, what's your Ruby version?

from lokalise_rails.

bodrovis avatar bodrovis commented on July 26, 2024

As for the second exception, I believe here's the workaround https://stackoverflow.com/questions/71332602/upgrading-to-ruby-3-1-causes-psychdisallowedclass-exception-when-using-yaml-lo

from lokalise_rails.

daniel-prause avatar daniel-prause commented on July 26, 2024

Hi there! Thanks for the quick response :-)!

My ruby version is 3.0.4!

The Gemfile looks like so:

# frozen_string_literal: true

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
git_source(:gitlab) { |repo| "https://gitlab.com/#{repo}.git" }

ruby '3.0.4'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '>= 7.0.4.1'

gem 'strscan', '3.0.2' # this needs to be manually kept in sync with CentOS
# Use Puma as the app server
gem 'puma', '~> 5.0'
# use dotenv rails - please leave this here, because this needs to be loaded before other gems!
gem 'dotenv-rails', require: 'dotenv/rails-now'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Turbolinks is replaced by turbo-rails starting from Rails 7
gem 'turbo-rails'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
gem 'lokalise_rails'
gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'activerecord-import'
gem 'breadcrumbs'
gem 'bunny', github: 're-gmbh/bunny'
gem 'cifs_client', gitlab: 'r-eco/c.hub-2.0/ruby_cifs'
gem 'cocoon'
gem 'concurrent-ruby', require: 'concurrent'
gem 'concurrent-ruby-edge', require: 'concurrent-edge'
gem 'concurrent-ruby-ext'
gem 'config' # configure application based on YAML, ENV & others
gem 'devise' # authentication
gem 'devise-i18n'
gem 'doorkeeper'
gem 'doorkeeper-i18n'
gem 'doorkeeper-jwt'
gem 'draper'
gem 'faraday'
gem 'faraday_middleware'
gem 'feature_flipper'
gem 'fx'
gem 'graphiql-rails'
gem 'graphql'
gem 'i18n-js', '< 4.0.0'
gem 'liquid' # needed for tagname templating in asset templates
gem 'nokogiri', '>= 1.14.3' # earlier version has security issue
gem 'oj'
gem 'pagy'
gem 'paranoia' # used for soft-deleting records
gem 'pg'
gem 'pghero', '>= 3.1.0', require: ENV['RAILS_PGHERO'].to_i == 1 # earlier version with vulnerability
gem 'pg_query', '>= 0.9.0'
gem 'prawn'
gem 'prawn-table'
gem 'pundit' # authorization
gem 'rack-cors'
gem 'rails_event_store'
gem 'rexml'
# Access the RE:based API via GraphQL
gem 'graphql-client'
gem 'ruby_event_store-sidekiq_scheduler'
gem 'safe-enum', github: 're-gmbh/ruby-safe-enum'
gem 'simple_form', github: 'heartcombo/simple_form'
gem 'sprockets-rails'
gem 'state_machines'
gem 'view_component'
gem 'will_paginate', '~> 3.3.0'
gem 'will_paginate-bootstrap-style'
# Tagging for equipment and equipment properties
gem 'acts-as-taggable-on', '~> 9.0'
# translate enum values
gem 'translate_enum'
# Background job processing
gem 'sidekiq', '<7'
gem 'sidekiq-cron'
gem 'sidekiq-limit_fetch'
gem 'sidekiq-unique-jobs'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

# wrapper around DataTables ajax methods
gem 'ajax-datatables-rails', github: 're-gmbh/ajax-datatables-rails'

# allow the duplication of associated child record objects when duplicating an active record model
gem 'amoeba', '~> 3.2.0'
gem 'roo', '~> 2.7', '>= 2.7.1'

gem 'rubyzip', '~> 2.3.2'

gem 'act-fluent-logger-rails', require: ENV['RAILS_LOG_TO_FLUENT'].to_i == 1
gem 'lograge', require: ENV['RAILS_LOG_TO_FLUENT'].to_i == 1
gem 'opentelemetry-exporter-otlp'
gem 'opentelemetry-instrumentation-action_pack'
gem 'opentelemetry-instrumentation-action_view'
gem 'opentelemetry-instrumentation-bunny'
gem 'opentelemetry-instrumentation-graphql'
gem 'opentelemetry-instrumentation-pg'
gem 'opentelemetry-instrumentation-rack'
gem 'opentelemetry-instrumentation-rails'
gem 'opentelemetry-instrumentation-sidekiq'
gem 'opentelemetry-sdk'
gem 'xxhash' # Fast (non-cryptographic) hashing

group :development, :test do
  # Call 'binding.pry' anywhere in the code to stop execution and get a debugger console
  gem 'debug' unless ENV['RM_INFO'] # new default debugger for rails 7; disabled when using RubyMine/IntelliJ
  gem 'i18n-tasks', '~> 0.9.34'
  # gem 'pry-byebug', platforms: %i[mri mingw x64_mingw]
  # gem 'pry-rails'
end

group :development do
  # TODO: replace me with the official source, when the update is through
  gem 'annotate', github: 'dabit/annotate_models', branch: 'rails-7'
  gem 'bullet'
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 4.1.0'
  # Display performance information such as SQL time and flame graphs for each request in your browser.
  # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
  gem 'brakeman', require: false
  gem 'listen', '~> 3.3'
  gem 'lookbook'
  gem 'parser', '3.1.2.1' # pin version for ruby 3.0.4 for rubocop
  gem 'pgcli-rails'
  gem 'rack-mini-profiler', '~> 2.0'
  gem 'rubocop', require: false
  gem 'rubocop-daemon', require: false
  gem 'rubocop-graphql', require: false
  gem 'rubocop-rails', require: false
  gem 'solargraph', require: false
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 3.26'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'cuprite' # better webdriver
  gem 'minitest-reporters'
  gem 'mocha' # Minitest built-in Mocks are PITA
  gem 'shoulda-context'
  gem 'shoulda-matchers'
  gem 'webdrivers'
  gem 'webmock' # mock http requests

  gem 'simplecov', require: false # test coverage analysis
  gem 'simplecov-cobertura', require: false
  gem 'timecop' # provides test helpers for time-related functionality
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

gem 'jsbundling-rails', '~> 1.1'

I found this link here (https://stackoverflow.com/questions/71332602/upgrading-to-ruby-3-1-causes-psychdisallowedclass-exception-when-using-yaml-lo) as well, but sadly it didn't change anything for me :/!

from lokalise_rails.

bodrovis avatar bodrovis commented on July 26, 2024

I believe the problem arises because of the faraday_middleware gem. Long story short, LokaliseRails uses Faraday v2 but the FaradayMiddleware requires Faraday v1. The newer Faraday v2 has a different approach: rather than relying on this middleware, they suggest adding individual components manually: https://github.com/lostisland/faraday_middleware#%EF%B8%8F-deprecation-warning-%EF%B8%8F

So, effectively there are two possible solutions:

  1. Keep things as is, use older faraday+middleware and stay on older LokaliseRails (the latest supported version should be picked automaticaly)
  2. Follow the guide that I've sent above and replace Middleware with newer solutions. In this case you'll have to understand which components you actually need (I can't say for sure, unfortunately). https://github.com/lostisland/awesome-faraday provides a huge list of all the available middleware

Now, as for the problems with Pshych, I don't think these are related to the LokaliseRails gem. Most likely, you have some unexpected characters in the YAML translation files themselves, and the loaders complains about these. I believe adding the following line to the application.rb should help (then again, I'm not sure which "unpermitted" objects your translations contain):

config.active_record.yaml_column_permitted_classes += [Symbol, Date, Time]

This is a more radical yet unfsafe approach, perhaps it'll help (though I have to say it really is unsafe):

config.active_record.use_yaml_unsafe_load = true

If nothing helps, please paste the contents of your translation file, I'll try to look into it

from lokalise_rails.

daniel-prause avatar daniel-prause commented on July 26, 2024

Hey, @bodrovis !

Thank you for your quick responses! They were super helpful!
The first solution was to throw out faraday_middleware from the project and upgrade the code to a faraday 2.x compatible syntax.

The second solution was to throw out symbolized values and use strings for values instead.

Another question: Is it possible to use more than just one path?
Within the project, we are using view components and we would like to use multiple paths for all the translation files.

Thank you in advance!

Kind regards

Daniel

from lokalise_rails.

bodrovis avatar bodrovis commented on July 26, 2024

Good day!

Unfortunately, by default the gem works only with a single path. However, you can try this approach https://github.com/bodrovis/lokalise_rails#running-tasks-programmatically Basically, one should create a script to perform importing/exporting, inherit from the global settings (though it's not mandatory) and set per-client options. Here's a very raw example:

require "#{Rails.root}/config/lokalise_rails.rb"

importer = LokaliseManager.importer({locales_path: "#{Rails.root}/custom_path/locales"}, LokaliseRails::GlobalConfig)
importer.import!

In the example above we override the global options with a custom locales path, and then start the importing process. If needed, all the options can be customized, including the API token, file format, and so on. Basically, inside this script you can create as many importers or exporters with custom locale paths.

These can be regular Ruby scripts, or you can create custom Rake tasks by using the base task as an example https://github.com/bodrovis/lokalise_rails/blob/master/lib/tasks/lokalise_rails_tasks.rake#L7

from lokalise_rails.

daniel-prause avatar daniel-prause commented on July 26, 2024

Thank you very very much for your effort!
It is a shame, that this is very seldom lately in this world!
Your tips and code examples were all super helpful!

I will try this out within the next few hours and give you feedback to this!

from lokalise_rails.

bodrovis avatar bodrovis commented on July 26, 2024

No problems at all, I'm glad to help :)

from lokalise_rails.

bodrovis avatar bodrovis commented on July 26, 2024

I'm going to close the ticket but feel free to reopen if this is still relevant.

from lokalise_rails.

Related Issues (7)

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.