]> git.cworth.org Git - sup/commitdiff
use gettext library to determine character set
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 9 Jan 2008 16:30:30 +0000 (08:30 -0800)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 16 Jan 2008 02:42:47 +0000 (18:42 -0800)
Previous character set detection was completely broken.

Rakefile
lib/sup.rb

index 1932f62c3a7204cc4bdbd82aa84eb300e31b8b3e..ec8c80424fbdb0fe6674abb9bb67abf7d9a58e8d 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -15,7 +15,7 @@ Hoe.new('sup', Redwood::VERSION) do |p|
   p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[2].gsub(/^\s+/, "")
   p.changes = p.paragraphs_of('History.txt', 0..0).join("\n\n")
   p.email = "wmorgan-sup@masanjin.net"
-  p.extra_deps = [['ferret', '>= 0.10.13'], ['ncurses', '>= 0.9.1'], ['rmail', '>= 0.17'], 'highline', 'net-ssh', ['trollop', '>= 1.7'], 'lockfile', 'mime-types']
+  p.extra_deps = [['ferret', '>= 0.10.13'], ['ncurses', '>= 0.9.1'], ['rmail', '>= 0.17'], 'highline', 'net-ssh', ['trollop', '>= 1.7'], 'lockfile', 'mime-types', 'gettext']
 end
 
 rule 'ss?.png' => 'ss?-small.png' do |t|
index 25809ddbe760bfb5ca2648713251bea77c528748..064e0af4e9f61200696ffd7bd164826540b5e4b2 100644 (file)
@@ -3,6 +3,7 @@ require 'yaml'
 require 'zlib'
 require 'thread'
 require 'fileutils'
+require 'gettext'
 require 'curses'
 
 class Object
@@ -49,16 +50,6 @@ module Redwood
   YAML_DOMAIN = "masanjin.net"
   YAML_DATE = "2006-10-01"
 
-## determine encoding and character set
-## probably a better way to do this
-  $ctype = ENV["LC_CTYPE"] || ENV["LANG"] || "en-US.utf-8"
-  $encoding =
-    if $ctype =~ /\.(.*)?/
-      $1
-    else
-      "utf-8"
-    end
-
 ## record exceptions thrown in threads nicely
   def reporting_thread name
     if $opts[:no_threads]
@@ -235,6 +226,15 @@ module Redwood
   module_function :log
 end
 
+## determine encoding and character set
+  $encoding = Locale.current.charset
+  if $encoding
+    Redwood::log "using character set encoding #{$encoding.inspect}"
+  else
+    Redwood::log "warning: can't find character set by using locale, defaulting to utf-8"
+    $encoding = "utf-8"
+  end
+
 ## now everything else (which can feel free to call Redwood::log at load time)
 require "sup/update"
 require "sup/suicide"