Import Upstream version 1.3.0

parents
# Changelog
## [1.3.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.3.0) - 2017-03-16
* Fixed Handlebars translations with options (@mikezaby)
* Fixed latest Rubocop offenses (@mikezaby)
* Dropped failing coveralls, fixed codeclimate (@tboerger)
## [1.2.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.2.0) - 2016-06-02
* Support for JSX files (@artemv)
* Fixed test suite, reduced test matrix (@tboerger)
## [1.1.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.1.0) - 2016-06-02
* Replace hyphens with underscores in locale var from DOM (@filib)
## [1.0.4](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.4) - 2016-05-31
* Support ES2015 template strings (@bradbarrow)
## [1.0.3](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.3) - 2015-11-03
* Stop using bundler within the core lib (@domcleal)
## [1.0.2](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.2) - 2015-03-30
* Fixes exception when parsing empty js/coffee files (@tboerger)
* Avoid methods defined in rake task exposing globally (@tboerger)
* Added better configuration options (@tboerger)
## [1.0.1](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.1) - 2015-02-24
* Added missing javascripts to the gemspec (@tboerger)
## [1.0.0](https://github.com/webhippie/gettext_i18n_rails_js/releases/tag/v1.0.0) - 2015-02-24
* Transfer from github.com/nubis/gettext_i18n_rails_js (@tboerger)
* Added TravisCI, Rubocop and Coveralls (@tboerger)
* Updated structure to my opinionated gem style (@tboerger)
* Changed default handlebars function to ```__``` (@tboerger)
* Added extended ```gettext_i18n_rails_js.yml``` (@tboerger)
The MIT License (MIT)
Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
Copyright (c) 2015 Webhippie <http://www.webhippie.de>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# GettextI18nRailsJs
[![Gem Version](http://img.shields.io/gem/v/gettext_i18n_rails_js.svg)](https://rubygems.org/gems/gettext_i18n_rails_js)
[![Build Status](https://secure.travis-ci.org/webhippie/gettext_i18n_rails_js.svg)](https://travis-ci.org/webhippie/gettext_i18n_rails_js)
[![Code Climate](https://codeclimate.com/github/webhippie/gettext_i18n_rails_js.svg)](https://codeclimate.com/github/webhippie/gettext_i18n_rails_js)
[![Test Coverage](https://codeclimate.com/github/webhippie/gettext_i18n_rails_js/badges/coverage.svg)](https://codeclimate.com/github/webhippie/gettext_i18n_rails_js)
[![Dependency Status](https://gemnasium.com/webhippie/gettext_i18n_rails_js.svg)](https://gemnasium.com/webhippie/gettext_i18n_rails_js)
Extends [gettext_i18n_rails](https://github.com/grosser/gettext_i18n_rails),
making your .PO files available to client side javascript as JSON. It will find
translations inside your .js, .coffee, .handlebars and .mustache files, then it
will create JSON versions of your .PO files so you can serve them with the rest
of your assets, thus letting you access all your translations offline from
client side javascript.
## Versions
This gem is tested on the following versions, it's also possible that it works
with older versions, but because of version bumps at `gettext_i18n_rails` and
`fast_gettext` we have dropped the older versions from the testing matrix:
* Ruby
* 2.1.0
* 2.2.0
* Rails
* 3.2.21
* 4.0.13
* 4.1.16
* 4.2.7
## Installation
```ruby
gem "gettext_i18n_rails_js", "~> 1.2.0"
```
## Usage
set up you rails application with gettext support as usual, afterwards just
execute the following rake task to export your translations to JSON:
```bash
rake gettext:po_to_json
```
Per default this will reconstruct the ```locale/<lang>/app.po``` structure as
javascript files inside ```app/assets/javascripts/locale/<lang>/app.js```
The gem provides the [Jed](https://github.com/SlexAxton/Jed) library to use the
generated javascript files. It also provides a global ```__``` function that
maps to `Jed#gettext`. The Jed instance used by the client side ```__```
function is pre-configured with the ```lang``` attribute specified in your main
HTML tag. Before anything, make sure your page's HTML tag includes a valid
```lang``` attribute, for example:
```haml
%html{ manifest: "", lang: I18n.locale }
```
Once you're sure your page is configured with a locale, then you should add
both your javascript locale files and the provided javascripts to your
application.js
```js
//= require_tree ./locale
//= require gettext/all
```
The default function name is ```window.__```, to avoid conflicts with
underscore.js. If you want to alias the function to something else in your
javascript you should also instruct the javascript and coffeescript parser to
look for a different function when finding your translations within the config
file ```config/gettext_i18n_rails_js.yml```, these are valid available options:
```yml
output_path: "app/assets/javascripts/locale"
handlebars_function: "__"
javascript_function: "__"
jed_options:
pretty: false
```
If you prefer an initializer file within your rails application you can use
that in favor of the YML configuration as well:
```ruby
GettextI18nRailsJs.config do |config|
config.output_path = "app/assets/javascripts/locale"
config.handlebars_function = "__"
config.javascript_function = "__"
config.jed_options = {
pretty: false
}
end
```
## Todo
* More deep testing against multiple Rails versions
* Extend the current test suite, especially handlebars
## Contributing
Fork -> Patch -> Spec -> Push -> Pull Request
## Authors
* [Thomas Boerger](https://github.com/tboerger)
* [Nubis](https://github.com/nubis)
* [Other contributors](https://github.com/webhippie/gettext_i18n_rails_js/graphs/contributors)
## License
MIT
## Copyright
```
Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
Copyright (c) 2015 Webhippie <http://www.webhippie.de>
```
#########################################################
# This file has been automatically generated by gem2tgz #
#########################################################
# -*- encoding: utf-8 -*-
# stub: gettext_i18n_rails_js 1.3.0 ruby lib
Gem::Specification.new do |s|
s.name = "gettext_i18n_rails_js".freeze
s.version = "1.3.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze]
s.authors = ["Thomas Boerger".freeze, "Nubis".freeze]
s.date = "2017-03-16"
s.description = " It will find translations inside your .js and .coffee files, then it will\n create JSON versions of your .PO files and will let you serve them with the\n rest of your assets, thus letting you access all your translations offline\n from client side javascript.\n".freeze
s.email = ["thomas@webhippie.de".freeze, "nubis@woobiz.com.ar".freeze]
s.files = ["CHANGELOG.md".freeze, "LICENSE".freeze, "README.md".freeze, "lib/assets/javascripts/gettext/all.js".freeze, "lib/gettext_i18n_rails_js.rb".freeze, "lib/gettext_i18n_rails_js/config.rb".freeze, "lib/gettext_i18n_rails_js/engine.rb".freeze, "lib/gettext_i18n_rails_js/parser.rb".freeze, "lib/gettext_i18n_rails_js/parser/base.rb".freeze, "lib/gettext_i18n_rails_js/parser/handlebars.rb".freeze, "lib/gettext_i18n_rails_js/parser/javascript.rb".freeze, "lib/gettext_i18n_rails_js/task.rb".freeze, "lib/gettext_i18n_rails_js/version.rb".freeze, "lib/tasks/gettext_i18n_rails_js_tasks.rake".freeze, "spec/fixtures/example.coffee".freeze, "spec/fixtures/example.handlebars".freeze, "spec/fixtures/example.js".freeze, "spec/gettext_i18n_rails_js/parser/handlebars_spec.rb".freeze, "spec/gettext_i18n_rails_js/parser/javascript_spec.rb".freeze, "spec/gettext_i18n_rails_js_spec.rb".freeze, "spec/spec_helper.rb".freeze, "spec/support/with_file.rb".freeze, "vendor/assets/javascripts/gettext/jed.js".freeze]
s.homepage = "https://github.com/webhippie/gettext_i18n_rails_js".freeze
s.licenses = ["MIT".freeze]
s.required_ruby_version = Gem::Requirement.new(">= 1.9.3".freeze)
s.rubygems_version = "2.5.2".freeze
s.summary = "Extends gettext_i18n_rails making your .po files available to client side javascript as JSON".freeze
s.test_files = ["spec/fixtures/example.coffee".freeze, "spec/fixtures/example.handlebars".freeze, "spec/fixtures/example.js".freeze, "spec/gettext_i18n_rails_js/parser/handlebars_spec.rb".freeze, "spec/gettext_i18n_rails_js/parser/javascript_spec.rb".freeze, "spec/gettext_i18n_rails_js_spec.rb".freeze, "spec/spec_helper.rb".freeze, "spec/support/with_file.rb".freeze]
if s.respond_to? :specification_version then
s.specification_version = 4
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
s.add_runtime_dependency(%q<gettext>.freeze, [">= 3.0.2"])
s.add_runtime_dependency(%q<gettext_i18n_rails>.freeze, [">= 0.7.1"])
s.add_runtime_dependency(%q<po_to_json>.freeze, [">= 1.0.0"])
s.add_runtime_dependency(%q<rails>.freeze, [">= 3.2.0"])
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
s.add_development_dependency(%q<yard>.freeze, [">= 0"])
else
s.add_dependency(%q<bundler>.freeze, [">= 0"])
s.add_dependency(%q<gettext>.freeze, [">= 3.0.2"])
s.add_dependency(%q<gettext_i18n_rails>.freeze, [">= 0.7.1"])
s.add_dependency(%q<po_to_json>.freeze, [">= 1.0.0"])
s.add_dependency(%q<rails>.freeze, [">= 3.2.0"])
s.add_dependency(%q<rake>.freeze, [">= 0"])
s.add_dependency(%q<rspec>.freeze, [">= 0"])
s.add_dependency(%q<yard>.freeze, [">= 0"])
end
else
s.add_dependency(%q<bundler>.freeze, [">= 0"])
s.add_dependency(%q<gettext>.freeze, [">= 3.0.2"])
s.add_dependency(%q<gettext_i18n_rails>.freeze, [">= 0.7.1"])
s.add_dependency(%q<po_to_json>.freeze, [">= 1.0.0"])
s.add_dependency(%q<rails>.freeze, [">= 3.2.0"])
s.add_dependency(%q<rake>.freeze, [">= 0"])
s.add_dependency(%q<rspec>.freeze, [">= 0"])
s.add_dependency(%q<yard>.freeze, [">= 0"])
end
end
//
// Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
// Copyright (c) 2015 Webhippie <http://www.webhippie.de>
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//= require gettext/jed
//= require_self
(function() {
var locales = this.locales || {};
var locale = document.getElementsByTagName('html')[0].lang;
if(!locale) {
console.warn('No locale found as an html attribute, using default.');
return;
}
locale = locale.replace(/-/g, "_");
var i18n = new Jed(locales[locale] || {});
window.__ = function() {
return i18n.gettext.apply(i18n, arguments);
};
window.n__ = function() {
return i18n.ngettext.apply(i18n, arguments);
};
window.s__ = function(key) {
return window.__(key).split('|').pop();
};
window.gettext = window.__;
window.ngettext = window.n__;
window.sgettext = window.s__;
window.i18n = i18n;
})();
# -*- coding: UTF-8 -*-
#
# Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
# Copyright (c) 2015 Webhippie <http://www.webhippie.de>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
gem "rails", version: ">= 3.2.0"
gem "gettext", version: ">= 3.0.2"
gem "gettext_i18n_rails", version: ">= 0.7.1"
gem "po_to_json", version: ">= 0.1.0"
require "rails"
require "gettext"
require "gettext_i18n_rails"
require "po_to_json"
require_relative "gettext_i18n_rails_js/version"
require_relative "gettext_i18n_rails_js/parser"
require_relative "gettext_i18n_rails_js/config"
require_relative "gettext_i18n_rails_js/engine"
module GettextI18nRailsJs
class << self
def config(&block)
@config ||= GettextI18nRailsJs::Config.new(&block)
end
end
end
# -*- coding: UTF-8 -*-
#
# Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
# Copyright (c) 2015 Webhippie <http://www.webhippie.de>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
module GettextI18nRailsJs
class Config
attr_accessor :output_path
attr_accessor :handlebars_function
attr_accessor :javascript_function
attr_accessor :jed_options
def initialize(&block)
@output_path = defaults[:output_path]
@handlebars_function = defaults[:handlebars_function]
@javascript_function = defaults[:javascript_function]
@jed_options = defaults[:jed_options].symbolize_keys
instance_eval(&block) if block_given?
end
protected
def defaults
file = ::Rails.root.join(
"config",
"gettext_i18n_rails_js.yml"
)
values = {
output_path: File.join(
"app",
"assets",
"javascripts",
"locale"
),
handlebars_function: "__",
javascript_function: "__",
jed_options: {
pretty: false
}
}
if file.exist?
yaml = YAML.load_file(file) || {}
values.deep_merge(
yaml
).with_indifferent_access
else
values.with_indifferent_access
end
end
end
end
# -*- coding: UTF-8 -*-
#
# Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
# Copyright (c) 2015 Webhippie <http://www.webhippie.de>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
module GettextI18nRailsJs
module Rails
class Engine < ::Rails::Engine
end
end
end
# -*- coding: UTF-8 -*-
#
# Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
# Copyright (c) 2015 Webhippie <http://www.webhippie.de>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
require_relative "parser/base"
require_relative "parser/javascript"
require_relative "parser/handlebars"
module GettextI18nRailsJs
module Parser
end
end
# -*- coding: UTF-8 -*-
#
# Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
# Copyright (c) 2015 Webhippie <http://www.webhippie.de>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
require "gettext/tools/xgettext"
require "gettext_i18n_rails/gettext_hooks"
module GettextI18nRailsJs
module Parser
module Base
extend self
# The gettext function name can be configured at the module level as
# gettext_function. This is to provide a way to avoid
# conflicts with other javascript libraries. You only need to define
# the base function name to replace "_" and all the other variants
# (s_, n_, N_) will be deduced automatically.
attr_accessor :gettext_function
def gettext_function
@gettext_function ||= "__"
end
# We're lazy and klumsy, so this is a regex based parser that looks for
# invocations of the various gettext functions. Once captured, we scan
# them once again to fetch all the function arguments. Invoke regex
# captures like this:
#
# javascript source: "#{ __('hello') } #{ __("wor)ld") }"
# matches:
# [0]: __('hello')
# [1]: __
# [2]: 'hello'
#
# javascript source: __('item', 'items', 33)
# matches:
# [0]: __('item', 'items', 33)
# [1]: __
# [2]: 'item', 'items', 33
#
# handlebars source: "{{ _ "foo"}}"
# matches:
# [0]: __('foo')
# [1]: __
# [2]: 'foo'
#
# handlebars source: "{{ _ "foo" "foos" 3}}"
# matches:
# [0]: __('foo', 'foos', 3)
# [1]: __
# [2]: 'foo', 'foos', 3
def parse(file, _msgids = [])
collect_for(file) do |function, arguments, line|
key = arguments.scan(
/('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*`)/
).collect do |match|
match.first[1..-2]
end.join(separator_for(function))
next if key == ""
results_for(key, file, line)
end
end
protected
def cleanup_value(value)
value
.tr("\n", "\n")
.tr("\t", "\t")
.tr("\0", "\0")
end
def separator_for(value)
if value == "n#{gettext_function}"
"\000"
else
"\004"
end
end
def results_for(key, file, line)
[
cleanup_value(key),
[file, line].join(":")
]
end
end
end
end
# -*- coding: UTF-8 -*-
#
# Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
# Copyright (c) 2015 Webhippie <http://www.webhippie.de>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
require "gettext/tools/xgettext"
require "gettext_i18n_rails/gettext_hooks"
require_relative "base"
module GettextI18nRailsJs
module Parser
module Handlebars
include Base
extend self
def target?(file)
[
/\.handlebars\Z/,
/\.handlebars.erb\Z/,
/\.hbs\Z/,
/\.hbs.erb\Z/,
/\.mustache\Z/,
/\.mustache.erb\Z/
].any? { |regexp| file.match regexp }
end
protected
def collect_for(value)
::File.read(
value
).scan(invoke_regex).collect do |_whole, function, arguments|
yield(function, arguments, 1)
end.compact
end
def invoke_regex
#
# * Matches the function handlebars helper call grouping "{{"
# * A parenthesis to start the arguments to the function
# * Then double quote string
# * Remaining arguments
# * Function call closing parenthesis
#
/
\B[{]{2}(
([snN]?#{gettext_function})
\s+
(
(["'])(?:\\?+.)*?\4
(?:\s+(["'])(?:\\?+.)*?\5)?
)
.*?
)
[}]{2}
/x
end
end
end
end
GettextI18nRails::GettextHooks.add_parser(
GettextI18nRailsJs::Parser::Handlebars
)
# -*- coding: UTF-8 -*-
#
# Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
# Copyright (c) 2015 Webhippie <http://www.webhippie.de>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
require "gettext/tools/xgettext"
require "gettext_i18n_rails/gettext_hooks"
require_relative "base"
module GettextI18nRailsJs
module Parser
module Javascript
include Base
extend self
def target?(file)