Skip to content

Commit

Permalink
cache translations in dpgettext() builtin
Browse files Browse the repository at this point in the history
do not load the translations again in every call,
check if the translations have been already loaded

fixes very slow start in yast ncurses menu
(yast/ycp-killer#467)
  • Loading branch information
Ladislav Slezak committed Jun 19, 2013
1 parent 9a7c4fb commit 9fa8174
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ruby/ycp/builtins.rb
Expand Up @@ -681,7 +681,16 @@ def self.dngettext (domain, singular, plural, num)
# Translates the text using the given text domain and path
def self.dpgettext (domain, dirname, text)
old_text_domain = FastGettext.text_domain
FastGettext.add_text_domain(domain, :path => dirname)

# remember the domain => file mapping, the same domain might be
# used from a different path, then we need to reload the translations
@textdomain_mapping ||= {}

# check if the domain is already loaded from the path
if @textdomain_mapping[domain] != dirname && !FastGettext::translation_repositories[domain]
FastGettext.add_text_domain(domain, :path => dirname)
@textdomain_mapping[domain.dup] = dirname.dup
end
FastGettext.text_domain = domain
return FastGettext::Translation::_(text)
ensure
Expand Down

0 comments on commit 9fa8174

Please sign in to comment.