Skip to content

Added option to only send specified locales #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
Copycopter Client
=================

[![Build Status](https://secure.travis-ci.org/copycopter/copycopter-ruby-client.png?branch=master)](http://travis-ci.org/copycopter/copycopter-ruby-client)

This is the Ruby on Rails client for
[Copycopter](https://github.com/copycopter/copycopter-server).
[Copycopter](https://github.com/copycopter/copycopter-server) with the addition to just send locales that are set as active to the copycopter server.

It uses I18n to access copy and translations from a Copycopter project.

Expand All @@ -24,6 +22,7 @@ In your `config/initializers/copycopter.rb`:
CopycopterClient.configure do |config|
config.api_key = 'YOUR API KEY HERE'
config.host = 'your-copycopter-server.herokuapp.com'
config.active_locales = [:en,:de]
end

The API key is on the project page. See `CopycopterClient::Configuration` for
Expand Down
4 changes: 2 additions & 2 deletions lib/copycopter_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Client
# @option options [String] :ca_file path to root certificate file for ssl verification
def initialize(options)
[:api_key, :host, :port, :public, :http_read_timeout,
:http_open_timeout, :secure, :logger, :ca_file].each do |option|
:http_open_timeout, :secure, :logger, :ca_file, :active_locales].each do |option|
instance_variable_set "@#{option}", options[option]
end
end
Expand Down Expand Up @@ -83,7 +83,7 @@ def deploy
private

attr_reader :host, :port, :api_key, :http_read_timeout,
:http_open_timeout, :secure, :logger, :ca_file
:http_open_timeout, :secure, :logger, :ca_file, :active_locales

def public?
@public
Expand Down
6 changes: 5 additions & 1 deletion lib/copycopter_client/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module CopycopterClient
class Configuration

# These options will be present in the Hash returned by {#to_hash}.
OPTIONS = [:api_key, :development_environments, :environment_name, :host,
OPTIONS = [:api_key, :development_environments, :environment_name, :active_locales, :host,
:http_open_timeout, :http_read_timeout, :client_name, :client_url,
:client_version, :port, :protocol, :proxy_host, :proxy_pass,
:proxy_port, :proxy_user, :secure, :polling_delay, :logger,
Expand Down Expand Up @@ -57,6 +57,9 @@ class Configuration
# @return [String] The name of the environment the application is running in
attr_accessor :environment_name

# @return [Array<String>] A list of locales that should be sent to the server
attr_accessor :active_locales

# @return [String] The name of the client library being used to send notifications (defaults to +Copycopter Client+)
attr_accessor :client_name

Expand Down Expand Up @@ -102,6 +105,7 @@ def initialize
self.polling_delay = 300
self.secure = false
self.test_environments = %w(test cucumber)
self.active_locales = %w(:en)
@applied = false
end

Expand Down
3 changes: 2 additions & 1 deletion lib/copycopter_client/i18n_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def translate(locale, key, options = {})
# Returns locales availabile for this Copycopter project.
# @return [Array<String>] available locales
def available_locales
super
cached_locales = cache.keys.map { |key| key.split('.').first }
(cached_locales + super).uniq.map { |locale| locale.to_sym }
end
Expand All @@ -48,7 +49,7 @@ def available_locales
# @param [Hash] options unused part of the I18n API
def store_translations(locale, data, options = {})
super
store_item(locale, data)
store_item(locale, data) if CopycopterClient.configuration.active_locales.include?(locale.to_sym)
end

private
Expand Down