Skip to content

Commit

Permalink
Merge pull request #6 from Hivebrite/master
Browse files Browse the repository at this point in the history
Add possibility to remove the 'var' keyword in order to use a global variable for locales
  • Loading branch information
tboerger authored Jun 1, 2018
2 parents 33388b9 + 63d9b48 commit 5c6d18f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/po_to_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def generate_for_jed(language, overwrite = {})
generated = build_json_for(build_jed_for(@parsed))

[
"var #{@options[:variable]} = #{@options[:variable]} || {};",
@options[:variable_locale_scope] ? 'var' : '',
"#{@options[:variable]} = #{@options[:variable]} || {};",
"#{@options[:variable]}['#{@options[:language]}'] = #{generated};"
].join(" ")
end
Expand Down Expand Up @@ -191,7 +192,8 @@ def parse_options(options)
defaults = {
pretty: false,
domain: "app",
variable: "locales"
variable: "locales",
variable_locale_scope: true
}

defaults.merge(options)
Expand Down
11 changes: 11 additions & 0 deletions spec/po_to_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@
).to be > 0
end
end
context "without locale scope variable" do
subject do
po_to_json.generate_for_jed("de", variable_locale_scope: false)
end

it "should output the var definition" do
expect(
subject.include?("locales = locales || {}; locales['de'] = ")
).to be_truthy
end
end
end

# describe "generate simple hashes" do
Expand Down

0 comments on commit 5c6d18f

Please sign in to comment.