As this patch is not going to be accepted which is fair:
http://redmine.ruby-lang.org/issues/show/1528
Alternative and light solution is to create own extension as below:
- locale.c -------------------------------------------
#include <locale.h>
#include <ruby.h>
#ifndef RSTRING_PTR
#define RSTRING_PTR(str) RSTRING(str)->ptr
#endif
VALUE Locale = Qnil;
VALUE method_setlocale(VALUE self, VALUE category, VALUE locale);
void Init_locale() {
Locale = rb_define_module("Locale");
rb_define_module_function(Locale, "setlocale", method_setlocale, 2);
rb_define_const(Locale, "LC_CTYPE", INT2NUM(0));
rb_define_const(Locale, "LC_NUMERIC", INT2NUM(1));
rb_define_const(Locale, "LC_TIME", INT2NUM(2));
rb_define_const(Locale, "LC_COLLATE", INT2NUM(3));
rb_define_const(Locale, "LC_MONETARY", INT2NUM(4));
rb_define_const(Locale, "LC_MESSAGES", INT2NUM(5));
rb_define_const(Locale, "LC_ALL", INT2NUM(6));
}
VALUE method_setlocale(VALUE self, VALUE category, VALUE locale) {
int c = NUM2INT(category);
char *r;
if(locale == Qnil) {
r = setlocale(c, NULL);
} else {
Check_Type(locale, T_STRING);
r = setlocale(c, RSTRING_PTR(locale));
}
return r == NULL ? Qnil : rb_str_new2(r);
}
- extconf.rb -------------------------------------------
require 'mkmf'
extension_name = 'locale'
dir_config(extension_name)
create_makefile(extension_name)
... and use:
require 'locale'
Locale::setlocale Locale::LC_CTYPE, ''
This is what I do in one of my projects and it works fine with Iconv,
note I use LC_CTYPE not LC_ALL to not affect numbers or dates
formatting.
Regards,
--
Adam Strzelecki | nanoant.com
--
Posted via http://www.ruby-forum.com/.