File: intl.c

package info (click to toggle)
libintl-gettext-ruby 0.11-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 124 kB
  • ctags: 8
  • sloc: ansic: 95; makefile: 49; ruby: 13
file content (123 lines) | stat: -rw-r--r-- 3,150 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/************************************************

 intl.c

 Copyright (C) 1999 HIRATA Naoto

************************************************/
#include "ruby.h"
#include <libintl.h>
#ifdef HAVE_LOCALE_H
#  include <locale.h>
#endif

VALUE gIntl;

static VALUE intl_initialize( self, domain )
    VALUE self;
    VALUE domain;
{
    char* lang;
    Check_Type( domain, T_STRING );
/*    setlocale( LC_MESSAGES, "" );*/
        setlocale( LC_ALL, "" );
    textdomain( STR2CSTR( domain ) );

    return Qnil;
}

static VALUE intl_bindtextdomain( self, domain, dirname )
    VALUE self;
    VALUE domain;
    VALUE dirname;
{
    char* new_dirname;

    Check_Type( domain, T_STRING );
    switch( TYPE( dirname ) ) {
    case T_STRING:
        new_dirname = bindtextdomain( STR2CSTR( domain ), STR2CSTR( dirname ) );
        break;
    case T_NIL:
        new_dirname = bindtextdomain( STR2CSTR( domain ), NULL );
        break;
    default:
        rb_raise( rb_eTypeError, "dirname is Not String or Null" );
    }

    return rb_str_new2( new_dirname );
}

static VALUE intl_dcgettext( self, domain, msgid, category )
    VALUE self;
    VALUE domain;
    VALUE msgid;
    VALUE category;
{
    char* msgstr;

    Check_Type( domain, T_STRING );
    Check_Type( msgid, T_STRING );
    Check_Type( category, T_FIXNUM );
    msgstr = dcgettext( STR2CSTR( domain ), STR2CSTR( msgid ), FIX2INT( category ) );

    return rb_str_new2( msgstr );
}

static VALUE intl_dgettext( self, domain, msgid )
    VALUE self;
    VALUE domain;
    VALUE msgid;
{
    char* msgstr;

    Check_Type( domain, T_STRING );
    Check_Type( msgid, T_STRING );
    msgstr = dgettext( STR2CSTR( domain ), STR2CSTR( msgid ) );

    return rb_str_new2( msgstr );
}

static VALUE intl_gettext( self, msgid )
    VALUE self;
    VALUE msgid;
{
    char* msgstr;

    Check_Type( msgid, T_STRING );
    msgstr = gettext( STR2CSTR( msgid ) );

    return rb_str_new2( msgstr );
}

static VALUE intl_textdomain( self, domain )
    VALUE self;
    VALUE domain;
{
    char* new_domain;

    Check_Type( domain, T_STRING );
    new_domain = textdomain( STR2CSTR( domain ) );

    return rb_str_new2( new_domain );
}

void Init_intl()
{
    gIntl = rb_define_class( "Intl", rb_cObject );
    rb_define_method( gIntl, "initialize", intl_initialize, 1 );
    rb_define_method( gIntl, "gettext", intl_gettext, 1 );
    rb_define_method( gIntl, "_", intl_gettext, 1 );
    rb_define_method( gIntl, "bindtextdomain", intl_bindtextdomain, 2 );
    rb_define_method( gIntl, "dcgettext", intl_dcgettext, 3 );
    rb_define_method( gIntl, "dgettext", intl_dgettext, 2 );
    rb_define_method( gIntl, "textdomain", intl_textdomain, 1 );

    rb_define_const( gIntl, "LC_ALL", INT2FIX( LC_ALL ) );
    rb_define_const( gIntl, "LC_COLLATE", INT2FIX( LC_COLLATE ) );
    rb_define_const( gIntl, "LC_CTYPE", INT2FIX( LC_CTYPE ) );
    rb_define_const( gIntl, "LC_MESSAGES", INT2FIX( LC_MESSAGES ) );
    rb_define_const( gIntl, "LC_MONETARY", INT2FIX( LC_MONETARY ) );
    rb_define_const( gIntl, "LC_NUMERIC", INT2FIX( LC_NUMERIC ) );
    rb_define_const( gIntl, "LC_TIME", INT2FIX( LC_TIME ) );
}