File: hello.rb

package info (click to toggle)
ruby-gettext 3.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,284 kB
  • ctags: 1,287
  • sloc: ruby: 9,178; makefile: 8
file content (37 lines) | stat: -rwxr-xr-x 720 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/ruby
# hello.rb - sample for _() and class.
#
# Copyright (C) 2001-2009 Masao Mutoh
# This file is distributed under the same license as gettext.

require 'rubygems'
require 'gettext'

class HelloWorld
  include GetText

  base_dir = File.dirname(__FILE__)
  bindtextdomain("hello", :path => File.join(base_dir, "locale"))

  def hello
    print _("Hello World\n")
  end
end

if __FILE__ == $0
  a = HelloWorld.new

  a.hello # Show in your locale

  old = GetText.locale
  p old.to_s # Show current locale

  # Change the locale to "en".
  GetText.set_locale("en")
  p GetText.locale.to_s
  a.hello # Show in English

  # Retrive original locale
  GetText.set_locale(old)
  a.hello # Show in your locale
end