Permalink
Browse files

Merge branch 'i18n-make-gettext-optional' of git://github.com/kou/yard

  • Loading branch information...
2 parents 0b7f5de + e7dc4c3 commit 4a131283ca2eca3d6dabb6e5c41941ffcbaad72e @lsegal committed Jul 9, 2012
Showing with 16 additions and 4 deletions.
  1. +9 −3 lib/yard/i18n/locale.rb
  2. +7 −1 spec/i18n/locale_spec.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
@@ -31,6 +28,15 @@ 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
+ log.warn "Need gettext gem for i18n feature:"
+ log.warn " gem install gettext"
+ return false
+ end
+
parser = GetText::PoParser.new
parser.report_warning = false
data = GetText::MoFile.new
@@ -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 ""

0 comments on commit 4a13128

Please sign in to comment.