Module: Localite::Scope

Included in:
Localite
Defined in:
lib/localite/scope.rb

Defined Under Namespace

Modules: Etest Classes: Scopes

Instance Method Summary collapse

Instance Method Details

#html(&block) ⇒ Object

The mode setting defines how the template engine deals with its parameters. In :html mode all parameters will be subject to HTML escaping, while in :text mode the parameters remain unchanged.



38
39
40
# File 'lib/localite/scope.rb', line 38

def html(&block)
  in_mode :html, &block
end

#modeObject



46
47
48
# File 'lib/localite/scope.rb', line 46

def mode
  Thread.current[:"localite:mode"] || :text
end

#scope(*args, &block) ⇒ Object

scope allows to set a scope around a translation. A scoped translation

Localite.scope("scope") do
  "msg".t
end

will look up “scope.msg” and “msg”, in that order, and return the first matching translation in the current locale. Scopes can be stacked; looking up a scoped translation

Localite.scope("outer") do
  Localite.scope("scope") do
    "msg".t
  end
end

will look up “outer.scope.msg”, “scope.msg”, “msg”.

If no translation will be found we look up the same entries in the base locale.



22
23
24
25
26
27
28
# File 'lib/localite/scope.rb', line 22

def scope(*args, &block)
  return yield if args.empty?

  scopes.exec(args.shift) do
    scope *args, &block
  end
end

#scopesObject



30
31
32
# File 'lib/localite/scope.rb', line 30

def scopes
  Thread.current[:"localite:scopes"] ||= Scopes.new
end

#text(&block) ⇒ Object



42
43
44
# File 'lib/localite/scope.rb', line 42

def text(&block)
  in_mode :text, &block
end