File: mp_lang.c

package info (click to toggle)
mped 3.3.17-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,288 kB
  • ctags: 1,635
  • sloc: ansic: 13,150; sh: 393; makefile: 232; perl: 66
file content (108 lines) | stat: -rw-r--r-- 2,502 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
/*

    mp - Programmer Text Editor

    i18n.

    Copyright (C) 1991-2005 Angel Ortega <angel@triptico.com>

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

    http://www.triptico.com

*/

#include "config.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "mp_core.h"
#include "mp_lang.h"

#ifdef CONFOPT_GETTEXT

#include <locale.h>
#include <libintl.h>

#else /* CONFOPT_GETTEXT */

extern void po2c_setlang(char * lang);
extern char * po2c_gettext(char * msgid);

#endif /* CONFOPT_GETTEXT */

/*******************
	Data
********************/

/*******************
	Code
********************/

/**
 * L - Translate a string
 * @msgid: the string to be translated
 *
 * Translate @msgid using the current language info. If no
 * translation string is found, the same @msgid is returned.
 */
char * L(char * msgid)
{
#ifdef CONFOPT_GETTEXT
	return(gettext(msgid));
#else
	return(po2c_gettext(msgid));
#endif
}


/**
 * mpl_set_language - Sets the current language
 * @langname: name of the language to be set
 *
 * Sets the current language for language-dependent strings.
 * The @langname can be a two letter standard or the english
 * name for the language. If the required language is not
 * found in the internal database, english is set.
 */
void mpl_set_language(char * langname)
{
#ifdef CONFOPT_GETTEXT

	if(setlocale(LC_ALL, langname) == NULL)
	{
		mp_log("Can't set locale '%s'\n", langname);
		setlocale(LC_ALL, "C");
	}

	bindtextdomain("minimum-profit", CONFOPT_PREFIX "/share/locale");
	textdomain("minimum-profit");

#else

	if(*langname == '\0')
	{
		/* if langname is "", get from the environment */
		if((langname=getenv("LANG")) == NULL)
		if((langname=getenv("LC_ALL")) == NULL)
		if((langname=getenv("LC_MESSAGES")) == NULL)
			langname="";
	}

	po2c_setlang(langname);
#endif
}