Skip to content

Commit

Permalink
i18n: add locale loading feature to YARD::RegistryStore
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 19, 2012
1 parent 629f3bb commit 8dbc596
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/yard/registry_store.rb
Expand Up @@ -19,6 +19,7 @@ def initialize
@notfound = {}
@loaded_objects = 0
@available_objects = 0
@locales = {}
@store[:root] = CodeObjects::RootObject.allocate
@store[:root].send(:initialize, nil, :root)
end
Expand Down Expand Up @@ -108,6 +109,13 @@ def values_for_type(type, reload = false)
# @return [CodeObjects::RootObject] the root object
def root; @store[:root] end

# @param [String] name the locale name.
# @return [I18n::Locale] the locale object for +name+.
# @since 0.8.3
def locale(name)
@locales[name] ||= load_locale(name)
end

# @param [String, nil] file the name of the yardoc db to load
# @return [Boolean] whether the database was loaded
def load(file = nil)
Expand Down Expand Up @@ -283,6 +291,13 @@ def load_root
end
end

def load_locale(name)
locale = I18n::Locale.new(name)
po_dir = "po"
locale.load(po_dir)
locale
end

def all_disk_objects
Dir.glob(File.join(objects_path, '**/*')).select {|f| File.file?(f) }
end
Expand All @@ -302,4 +317,4 @@ def write_checksums
end
end
end
end
end
9 changes: 9 additions & 0 deletions spec/registry_store_spec.rb
Expand Up @@ -302,4 +302,13 @@ def saves_to_multidb
@store.destroy(true).should == true
end
end

describe '#locale' do
it "should load ./po/LOCALE_NAME.po" do
fr_locale = I18n::Locale.new("fr")
I18n::Locale.should_receive(:new).with("fr").and_return(fr_locale)
fr_locale.should_receive(:load).with("po")
@store.locale("fr").should == fr_locale
end
end
end

0 comments on commit 8dbc596

Please sign in to comment.