~ubuntu-branches/ubuntu/natty/xfce4-weather-plugin/natty-proposed

« back to all changes in this revision

Viewing changes to panel-plugin/translate.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez, Simon Huggins, Yves-Alexis Perez
  • Date: 2007-12-08 19:28:17 UTC
  • mfrom: (0.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071208192817-xjr2u2eshv19ndp5
Tags: 0.6.2-1
[ Simon Huggins ]
* debian/control: Move fake Homepage field to a real one now dpkg
  supports it.
* Add Vcs-* headers to debian/control

[ Yves-Alexis Perez ]
* New upstream release.
* debian/control:
  - updated standard versions to 3.7.3.
  - updated my email to the debian.org one.
* debian/copyright: updated copyrights, authors and license.
* debian/NEWS: remove tab at beginning of lines. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* vim: set expandtab ts=8 sw=4: */
2
 
 
3
 
/*  This program is free software; you can redistribute it and/or modify
4
 
 *  it under the terms of the GNU General Public      as published by
5
 
 *  the Free Software Foundation; either version 2 of the     , or
6
 
 *  (at your option) any later version.
7
 
 *
8
 
 *  This program is distributed in the hope that it will be useful,
9
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 *  GNU Library General Public      for more details.
12
 
 *
13
 
 *  You should have received a copy of the GNU General Public     
14
 
 *  along with this program; if not, write to the Free Software
15
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 
 */
17
 
 
18
 
#ifdef HAVE_CONFIG_H
19
 
#include <config.h>
20
 
#endif
21
 
 
22
 
#include <string.h>
23
 
#include <time.h>
24
 
 
25
 
#include "parsers.h"
26
 
#include "get_data.h"
27
 
#include "plugin.h"
28
 
#include "translate.h"
29
 
 
30
 
 
31
 
static const gchar *desc_strings[] = {
32
 
    N_("Snow to Rain"),
33
 
    N_("Becoming Cloudy"),
34
 
    N_("Blizzard"),
35
 
    N_("Blizzard Conditions"),
36
 
    N_("Blowing Snow"),
37
 
    N_("Chance of Rain"),
38
 
    N_("Chance of Rain/Snow"),
39
 
    N_("Chance of Showers"),
40
 
    N_("Chance of Snow"),
41
 
    N_("Chance of Snow/Rain"),
42
 
    N_("Chance of T-Storm"),
43
 
    N_("Clear"),
44
 
    N_("Clearing"),
45
 
    N_("Clouds"),
46
 
    N_("Cloudy"),
47
 
    N_("Cloudy Periods"),
48
 
    N_("Continued Hot"),
49
 
    N_("Cumulonimbus Clouds Observed"),
50
 
    N_("Drifting Snow"),
51
 
    N_("Drizzle"),
52
 
    N_("Dry"),
53
 
    N_("Fair"),
54
 
    N_("Flurries"),
55
 
    N_("Fog"),
56
 
    N_("Freezing Drizzle"),
57
 
    N_("Freezing Rain"),
58
 
    N_("Freezing Rain/Snow"),
59
 
    N_("Frozen Precip"),
60
 
    N_("Hazy"),
61
 
    N_("Heavy Rain"),
62
 
    N_("Heavy Snow"),
63
 
    N_("Hot And Humid"),
64
 
    N_("Ice Crystals"),
65
 
    N_("Ice/Snow Mixture"),
66
 
    N_("Increasing Clouds"),
67
 
    N_("Isolated Showers"),
68
 
    N_("Light Rain"),
69
 
    N_("Light Snow"),
70
 
    N_("Lightning Observed"),
71
 
    N_("mild and breezy"),
72
 
    N_("Mist"),
73
 
    N_("Mostly Clear"),
74
 
    N_("Mostly Cloudy"),
75
 
    N_("Mostly Sunny"),
76
 
    N_("N/A"),
77
 
    N_("Occasional Sunshine"),
78
 
    N_("Overcast"),
79
 
    N_("Partial Clearing"),
80
 
    N_("Partial Sunshine"),
81
 
    N_("Partly Cloudy"),
82
 
    N_("Partly Sunny"),
83
 
    N_("Rain"),
84
 
    N_("Rain and Snow"),
85
 
    N_("Rain or Snow"),
86
 
    N_("Rain Showers"),
87
 
    N_("Rain to Snow"),
88
 
    N_("Rain / Snow Showers"),
89
 
    N_("Showers"),
90
 
    N_("Sleet"),
91
 
    N_("Sleet and Snow"),
92
 
    N_("Smoke"),
93
 
    N_("Snow"),
94
 
    N_("Snow and Rain"),
95
 
    N_("Snow or Rain"),
96
 
    N_("Snow Showers"),
97
 
    N_("Sunny"),
98
 
    N_("Thunder"),
99
 
    N_("Thunder storms"),
100
 
    N_("Variable Cloudiness"),
101
 
    N_("Variable Clouds"),
102
 
    N_("Windy"),
103
 
    N_("Wintry Mix"),
104
 
    N_("Showers in the Vicinity"),
105
 
    N_("Light Rain Shower"),
106
 
    N_("Showers Late"),
107
 
    N_("PM Showers"),
108
 
    N_("Light Rain / Wind"),
109
 
    N_("Scattered Showers"),
110
 
    N_("PM Light Rain"),
111
 
    N_("AM Showers"),
112
 
    N_("AM Light Rain"),
113
 
    N_("Partly Cloudy and Windy"),
114
 
    N_("Few Showers"),
115
 
    N_("Light Drizzle"),
116
 
    N_("Clouds Early / Clearing Late"),
117
 
    N_("Mostly Cloudy and Windy"),
118
 
    N_("Rain / Snow"),
119
 
    N_("Rain and Sleet"),
120
 
    N_("Snow Showers Late"),
121
 
    N_("Light Drizzle and Windy"),
122
 
    N_("Snow Shower"),
123
 
    N_("Snow Showers Early"),
124
 
    N_("Few Snow Showers"),
125
 
    NULL
126
 
};
127
 
 
128
 
static const gchar *bard_strings[] = {
129
 
    N_("rising"), 
130
 
    N_("steady"), 
131
 
    N_("falling"), 
132
 
    NULL
133
 
};
134
 
 
135
 
static const gchar *risk_strings[] = {
136
 
    N_("Low"), 
137
 
    N_("Moderate"), 
138
 
    N_("High"), 
139
 
    N_("Very High"), 
140
 
    N_("Extreme"), 
141
 
    NULL
142
 
};
143
 
 
144
 
static const gchar *wdirs[] = {
145
 
    N_("S"), 
146
 
    N_("SSW"), 
147
 
    N_("SW"), 
148
 
    N_("WSW"), 
149
 
    N_("W"), 
150
 
    N_("WNW"), 
151
 
    N_("NW"), 
152
 
    N_("NNW"), 
153
 
    N_("N"),
154
 
    N_("NNE"),
155
 
    N_("NE"),
156
 
    N_("ENE"),
157
 
    N_("E"), 
158
 
    N_("ESE"), 
159
 
    N_("SE"), 
160
 
    N_("SSE"), 
161
 
    NULL
162
 
};
163
 
 
164
 
static const gchar *
165
 
translate_str(const gchar **loc_strings, 
166
 
              const gchar  *str)
167
 
{
168
 
    gint loc_string_len, str_len;
169
 
    guint i;
170
 
 
171
 
    if (str == NULL)
172
 
        return "?";
173
 
 
174
 
    str_len = strlen(str);
175
 
 
176
 
    if (str_len < 1)
177
 
        return "?";
178
 
 
179
 
    for (i = 0; loc_strings[i] != NULL; i++)
180
 
    {
181
 
        loc_string_len = strlen(loc_strings[i]);
182
 
 
183
 
        if (str_len != loc_string_len)
184
 
            continue;
185
 
        
186
 
        if (str[0] != loc_strings[i][0])
187
 
            continue;
188
 
 
189
 
        if (!g_ascii_strncasecmp(loc_strings[i], str, str_len)) 
190
 
            return _(loc_strings[i]);
191
 
    }
192
 
 
193
 
    return str;
194
 
}
195
 
 
196
 
const gchar *
197
 
translate_bard (const gchar *bard)
198
 
{
199
 
    return translate_str(bard_strings, bard);
200
 
}
201
 
 
202
 
const gchar *
203
 
translate_risk (const gchar *risk)
204
 
{
205
 
    return translate_str(risk_strings, risk);
206
 
}
207
 
 
208
 
const gchar *
209
 
translate_desc (const gchar *desc)
210
 
{
211
 
    return translate_str(desc_strings, desc);
212
 
}
213
 
 
214
 
/* used by translate_lsup and translate_time */
215
 
static void
216
 
_fill_time(struct tm   *time, 
217
 
           const gchar *hour, 
218
 
           const gchar *minute,
219
 
           const gchar *am)
220
 
{
221
 
    time->tm_hour = atoi(hour);
222
 
 
223
 
    if (am[0] == 'P' && time->tm_hour != 12) /* PM or AM */
224
 
        time->tm_hour += 12;
225
 
    
226
 
    time->tm_min = atoi(minute);
227
 
    time->tm_sec = 0;
228
 
    time->tm_isdst = -1;
229
 
}
230
 
 
231
 
 
232
 
 
233
 
#define HDATE_N sizeof(gchar) * 100
234
 
gchar *
235
 
translate_lsup (const gchar *lsup)
236
 
{
237
 
    gchar *hdate;
238
 
    struct tm time;
239
 
    gint size = 0, i = 0;
240
 
    
241
 
    
242
 
    gchar **lsup_split; 
243
 
    
244
 
    if (lsup == NULL || strlen(lsup) == 0)
245
 
        return NULL;
246
 
    
247
 
    /* 10/17/04 5:55 PM Local Time */
248
 
    if ((lsup_split = g_strsplit_set(lsup, " /:", 8)) == NULL)
249
 
        return NULL;
250
 
 
251
 
    while(lsup_split[i++]) 
252
 
        size++;
253
 
    
254
 
    if (size != 8)
255
 
    {
256
 
        g_strfreev(lsup_split);
257
 
        return NULL;
258
 
    }
259
 
 
260
 
    time.tm_mon = atoi(lsup_split[0]) - 1;
261
 
    time.tm_mday = atoi(lsup_split[1]);
262
 
    time.tm_year = atoi(lsup_split[2]) + 100;
263
 
 
264
 
    _fill_time(&time, lsup_split[3], lsup_split[4], lsup_split[5]);
265
 
 
266
 
    g_strfreev(lsup_split);
267
 
    
268
 
    if (mktime(&time) != -1)
269
 
    {
270
 
        hdate = g_malloc(HDATE_N);
271
 
 
272
 
        strftime(hdate, HDATE_N, _("%x at %X Local Time"), &time);
273
 
        
274
 
        return hdate;
275
 
    }
276
 
    else
277
 
        return NULL;
278
 
}
279
 
 
280
 
#define DAY_LOC_N sizeof(gchar) * 20
281
 
gchar *
282
 
translate_day (const gchar *day)
283
 
{
284
 
    gint wday = -1;
285
 
    guint i;
286
 
    const gchar *days[] = {
287
 
      "su", "mo", "tu", "we", "th", "fr", "sa", NULL
288
 
    };
289
 
    gchar *day_loc;
290
 
    
291
 
    if (day == NULL || strlen(day) < 2)
292
 
        return NULL;
293
 
    
294
 
    for (i = 0; days[i] != NULL; i++)
295
 
        if (!g_ascii_strncasecmp(day, days[i], 2))
296
 
            wday = i;
297
 
 
298
 
    if (wday == -1)
299
 
        return NULL;
300
 
    else
301
 
    {
302
 
        struct tm time;
303
 
        
304
 
        time.tm_wday = wday;
305
 
 
306
 
        day_loc = g_malloc(DAY_LOC_N);
307
 
 
308
 
        strftime(day_loc, DAY_LOC_N, "%A", &time);
309
 
 
310
 
        return day_loc;
311
 
    }
312
 
}
313
 
 
314
 
/* NNW  VAR */
315
 
gchar *
316
 
translate_wind_direction (const gchar *wdir)
317
 
{
318
 
    gint wdir_len;
319
 
    guint i;
320
 
    gchar *wdir_loc;
321
 
 
322
 
    if (wdir == NULL || (wdir_len = strlen(wdir)) < 1)
323
 
        return NULL;
324
 
 
325
 
    if (strchr(wdir, '/')) /* N/A */
326
 
        return NULL;
327
 
    
328
 
    /*
329
 
     * If the direction code can be translated, then translated the
330
 
     * whole code so that it can be correctly translated in CJK (and
331
 
     * possibly Finnish).  If not, use the old behaviour where
332
 
     * individual direction codes are successively translated.
333
 
     */
334
 
    if (g_ascii_strcasecmp(wdir, _(wdir)) != 0)
335
 
        wdir_loc = g_strdup(_(wdir));
336
 
    else
337
 
    {
338
 
        wdir_loc = g_strdup("");
339
 
        for (i = 0; i < strlen(wdir); i++)
340
 
            {
341
 
                gchar wdir_i[2];
342
 
                gchar *tmp;
343
 
 
344
 
                wdir_i[0] = wdir[i];
345
 
                wdir_i[1] = '\0';
346
 
 
347
 
                tmp = g_strdup_printf("%s%s", wdir_loc,
348
 
                        translate_str(wdirs, wdir_i));
349
 
                g_free(wdir_loc);
350
 
                wdir_loc = tmp;
351
 
            }
352
 
        
353
 
    }
354
 
    
355
 
    return wdir_loc;
356
 
}
357
 
 
358
 
/* calm or a number */
359
 
gchar *
360
 
translate_wind_speed (const gchar *wspeed,
361
 
                      units        unit)
362
 
{
363
 
    gchar *wspeed_loc;
364
 
 
365
 
    if (g_ascii_strcasecmp(wspeed, "calm") == 0)
366
 
        wspeed_loc = g_strdup(_("calm"));
367
 
    else if (g_ascii_strcasecmp(wspeed, "N/A") == 0)
368
 
        wspeed_loc = g_strdup(_("N/A"));
369
 
    else
370
 
        wspeed_loc = g_strdup_printf("%s %s", wspeed, get_unit(unit, WIND_SPEED));
371
 
    
372
 
    return wspeed_loc;
373
 
}
374
 
 
375
 
/* 8:13 AM */
376
 
#define TIME_LOC_N sizeof(gchar) * 20
377
 
gchar *
378
 
translate_time (const gchar *time)
379
 
{
380
 
    gchar **time_split, *time_loc;
381
 
    int i = 0, size = 0;
382
 
    struct tm time_tm;
383
 
 
384
 
    if (strlen(time) == 0)
385
 
        return NULL;
386
 
 
387
 
    time_split = g_strsplit_set(time, ": ", 3);
388
 
 
389
 
    while(time_split[i++])
390
 
        size++;
391
 
 
392
 
    if (size != 3)
393
 
        return NULL;
394
 
 
395
 
    time_loc = g_malloc(TIME_LOC_N);
396
 
 
397
 
    _fill_time(&time_tm, time_split[0], time_split[1], time_split[2]);
398
 
    g_strfreev(time_split);
399
 
 
400
 
    strftime(time_loc, TIME_LOC_N, "%X", &time_tm);
401
 
 
402
 
    return time_loc;
403
 
}
404
 
 
405
 
/* Unlimited or a number */
406
 
gchar *
407
 
translate_visibility (const gchar *vis,
408
 
                      units        unit)
409
 
{
410
 
    gchar *vis_loc;
411
 
 
412
 
    if (g_ascii_strcasecmp(vis, "Unlimited") == 0)
413
 
        vis_loc = g_strdup(_("Unlimited"));
414
 
    else
415
 
        vis_loc = g_strdup_printf("%s %s", vis, get_unit(unit, VIS));
416
 
    
417
 
    return vis_loc;
418
 
}