/rusxmms/librcc

To get this branch, use:
bzr branch http://suren.me/webbzr/rusxmms/librcc

« back to all changes in this revision

Viewing changes to src/recode.c

  • Committer: Suren A. Chilingaryan
  • Date: 2005-07-29 03:26:28 UTC
  • Revision ID: Arch-1:ds@dside.dyndns.org--darksoft-2004%librcc--main--0.1--patch-23
Translation
    - Language Translation using libtranslate is implemented
    - Autoengine sets current charset (option)

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#include "rccstring.h"
10
10
#include "rccconfig.h"
11
11
#include "rccdb4.h"
 
12
#include "rcctranslate.h"
12
13
 
13
14
 
14
15
 
37
38
    rcc_iconv icnv = NULL;
38
39
    rcc_string result;
39
40
    rcc_option_value usedb4;
 
41
    const char *charset;
40
42
 
41
43
    if (!ctx) {
42
44
        if (rcc_default_ctx) ctx = rcc_default_ctx;
66
68
    if (err) return NULL;
67
69
    
68
70
    charset_id = rccIConvAuto(ctx, class_id, buf, len);
69
 
    if (charset_id != (rcc_autocharset_id)-1) icnv = ctx->iconv_auto[charset_id];
 
71
    if (charset_id != (rcc_autocharset_id)-1) {
 
72
        icnv = ctx->iconv_auto[charset_id];
 
73
        if (rccGetOption(ctx, RCC_OPTION_AUTOENGINE_SET_CURRENT)) {
 
74
            charset = rccGetAutoCharsetName(ctx, charset_id);
 
75
            rccSetCharsetByName(ctx, class_id, charset);
 
76
        }
 
77
    }
70
78
    else icnv = ctx->iconv_from[class_id];
71
79
 
72
80
    if (icnv) {
73
 
        ret = rccIConv(ctx, icnv, buf, len);
 
81
        ret = rccIConvInternal(ctx, icnv, buf, len);
74
82
        if (ret == (size_t)-1) return NULL;
75
83
        result = rccCreateString(language_id, ctx->tmpbuffer, ret);
76
84
    } else {
92
100
    char *result;
93
101
    char *prefix, *name;
94
102
    const char *utfstring;
 
103
    char *translated = NULL;
95
104
    rcc_language_config config;
96
105
    rcc_language_id language_id;
 
106
    rcc_language_id current_language_id;
97
107
    rcc_class_type class_type;
98
108
    rcc_iconv icnv;
99
109
 
117
127
    if (err) return NULL;
118
128
 
119
129
    class_type = rccGetClassType(ctx, class_id);
 
130
    if ((class_type != RCC_CLASS_FS)&&(rccGetOption(ctx, RCC_OPTION_TRANSLATE))) {
 
131
        current_language_id = rccGetCurrentLanguage(ctx);
 
132
        if (current_language_id != language_id) {
 
133
            if ((config->trans)&&(config->translang != current_language_id)) {
 
134
                rccTranslateClose(config->trans);
 
135
                config->trans = NULL;
 
136
            }
 
137
            if (!config->trans) {
 
138
                config->trans = rccTranslateOpen(rccGetLanguageName(ctx, language_id), rccGetLanguageName(ctx, current_language_id));
 
139
                config->translang = current_language_id;
 
140
            }
 
141
            if (config->trans) {
 
142
                translated = rccTranslate(config->trans, utfstring);
 
143
                if (translated) {
 
144
                    language_id = current_language_id;
 
145
                    
 
146
                    config = rccGetConfig(ctx, language_id);
 
147
                    if (!config) {
 
148
                        free(translated);
 
149
                        return NULL;
 
150
                    }
 
151
 
 
152
                    err = rccConfigConfigure(config);
 
153
                    if (err) {
 
154
                        free(translated);
 
155
                        return NULL;
 
156
                    }
 
157
                }
 
158
            }
 
159
        }
 
160
    }
 
161
    
120
162
    if ((class_type == RCC_CLASS_FS)&&(rccGetOption(ctx, RCC_OPTION_AUTODETECT_FS_NAMES))) {
121
163
            if (rccIsASCII(utfstring)) {
122
164
                result = rccStringExtractString(buf);
141
183
 
142
184
    icnv =  config->iconv_to[class_id];
143
185
    if (icnv) {
144
 
        newlen = rccIConv(ctx, icnv, rccStringGetString((const char*)buf), newlen);
 
186
        newlen = rccIConvInternal(ctx, icnv, translated?translated:utfstring, newlen);
 
187
        if (translated) free(translated);
145
188
        if (newlen == (size_t)-1) return NULL;
146
189
 
147
190
        result = rccCreateResult(ctx, newlen);
148
191
        if (rlen) *rlen = newlen;
149
192
    } else {
150
 
        result = rccStringExtractString(buf);
151
 
        if (rlen) *rlen = newlen;
 
193
        if (translated) {
 
194
            result = translated;
 
195
            if (rlen) *rlen = strlen(result);
 
196
        } else {
 
197
            result = rccStringExtractString(buf);
 
198
            if (rlen) *rlen = newlen;
 
199
        }
152
200
    }    
153
201
    
154
202
    return result;
274
322
    
275
323
    icnv = rccIConvOpen("UTF-8", charset);
276
324
    if (icnv) {
277
 
        res = rccIConv(ctx, icnv, buf, len);
 
325
        res = rccIConvInternal(ctx, icnv, buf, len);
278
326
        rccIConvClose(icnv);
279
327
        if (res == (size_t)-1) return NULL;
280
328
        return rccCreateString(language_id, ctx->tmpbuffer, res);
293
341
    
294
342
    icnv = rccIConvOpen(charset, "UTF-8");
295
343
    if (icnv) {
296
 
        res = rccIConv(ctx, icnv, rccStringGetString(buf), res);
 
344
        res = rccIConvInternal(ctx, icnv, rccStringGetString(buf), res);
297
345
        rccIConvClose(icnv);
298
346
        if (res == (size_t)-1) return NULL;
299
347
        
321
369
 
322
370
    icnv = rccIConvOpen(charset, "UTF-8");
323
371
    if (icnv) {
324
 
        res = rccIConv(ctx, icnv, str, 0);
 
372
        res = rccIConvInternal(ctx, icnv, str, 0);
325
373
        rccIConvClose(icnv);
326
374
        free(utf8);
327
375
 
349
397
    
350
398
    icnv = rccIConvOpen("UTF-8", charset);
351
399
    if (icnv) {
352
 
        res = rccIConv(ctx, icnv, buf, len);
 
400
        res = rccIConvInternal(ctx, icnv, buf, len);
353
401
        rccIConvClose(icnv);
354
402
 
355
403
        if (res == (size_t)-1) return NULL;
373
421
    icnv = rccIConvOpen(to, from);
374
422
    if (!icnv) return NULL;
375
423
 
376
 
    res = rccIConv(ctx, icnv, buf, len);
 
424
    res = rccIConvInternal(ctx, icnv, buf, len);
377
425
    rccIConvClose(icnv);
378
426
    
379
427
    if (res == (size_t)-1) return NULL;