Skip to content

Commit

Permalink
i18n: make gettext gem optional
Browse files Browse the repository at this point in the history
Require gettext related files lazy and ignore LoadError.
  • Loading branch information
kou committed Jun 10, 2012
1 parent 67f5351 commit dadde5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/yard/i18n/locale.rb
@@ -1,6 +1,3 @@
require "gettext/tools/poparser"
require "gettext/runtime/mofile"

module YARD
module I18n
# +Locale+ is a unit of translation. It has {#name} and a set of
Expand Down Expand Up @@ -31,6 +28,13 @@ def load(locale_directory)
po_file = File.join(locale_directory, "#{@name}.po")
return false unless File.exist?(po_file)

begin
require "gettext/tools/poparser"
require "gettext/runtime/mofile"
rescue LoadError
return false
end

parser = GetText::PoParser.new
parser.report_warning = false
data = GetText::MoFile.new
Expand Down
8 changes: 7 additions & 1 deletion spec/i18n/locale_spec.rb
Expand Up @@ -21,7 +21,13 @@ def locale(name)
@locale.load('foo').should == false
end

it "should return true for existent PO" do
have_gettext_gem = true
begin
require "gettext/tools/poparser"
rescue LoadError
have_gettext_gem = false
end
it "should return true for existent PO", :if => have_gettext_gem do
data = <<-eop
msgid ""
msgstr ""
Expand Down

0 comments on commit dadde5a

Please sign in to comment.