Skip to content

A kinda streaming YAML serializer for the Rosette internationalization platform.

Notifications You must be signed in to change notification settings

rosette-proj/rosette-serializer-yaml

Repository files navigation

Build Status Code Climate Test Coverage

rosette-serializer-yaml

Provides a way of writing YAML files from lists of translations for the Rosette internationalization platform.

Installation

gem install rosette-serializer-yaml

Then, somewhere in your project:

require 'rosette/serializers/yaml-serializer'

Introduction

This library is generally meant to be used with the Rosette internationalization platform. rosette-serializer-yaml is capable of writing translations in YAML file format, specifically those that use the structure of one of the following:

  1. Ruby on Rails dotted key notation.

Additional types of YAML structure are straightforward to support. Open an issue or pull request if you'd like to see support for another structure.

Usage with rosette-server

Let's assume you're configuring an instance of Rosette::Server. Adding YAML Rails/dotted key serialization support would cause your configuration to look something like this:

# config.ru
require 'rosette/core'
require 'rosette/serializer/yaml-serializer'

rosette_config = Rosette.build_config do |config|
  config.add_repo('my_awesome_repo') do |repo_config|
    repo.add_serializer('yaml', format: 'yaml/rails')
  end
end

server = Rosette::Server::ApiV1.new(rosette_config)
run server

Serializers support a set of configuration options, including adding pre-processors. Preprocessors are applied before translations are serialized. Adding the normalization pre-processor, for example, looks like this:

repo.add_serializer('yaml', format: 'yaml/rails') do |serializer_config|
  serializer_config.add_preprocessor('normalization') do |pre_config|
    pre_config.set_normalization_form(:nfc)
  end
end

Standalone Usage

While most of the time rosette-serializer-yaml will probably be used alongside rosette-server (or similar), there may arise use cases where someone might want to use it on its own. The write_key_value method on RailsSerializer writes a key/value pair to the underlying stream:

stream = StringIO.new
locale = Rosette::Core::Locale.parse('ja-JP')
serializer = Rosette::Serializer::YamlSerializer::RailsSerializer.new(stream, locale)

serializer.write_key_value('foo', 'bar')
serializer.flush

# ja:
#   foo: bar
stream.string

Requirements

This project must be run under jRuby. It uses expert to manage java dependencies via Maven. Run bundle exec expert install in the project root to download and install java dependencies.

Running Tests

bundle exec rake or bundle exec rspec should do the trick.

Authors

About

A kinda streaming YAML serializer for the Rosette internationalization platform.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages