1 /*
2  *  Multi-language Support - language codes
3  *  Copyright (C) 2012 Adam Sutton
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __TVH_LANG_CODES_H__
20 #define __TVH_LANG_CODES_H__
21 
22 #include "redblack.h"
23 
24 typedef struct lang_code
25 {
26   const char *code2b; ///< ISO 639-2 B
27   const char *code1;  ///< ISO 639-1
28   const char *code2t; ///< ISO 639-2 T
29   const char *desc;   ///< Description
30   const char *locale; ///< Locale variants (like US|GB or DE|BE)
31 } lang_code_t;
32 
33 extern const lang_code_t lang_codes[];
34 
35 /* Convert code to preferred internal code */
36 const char *lang_code_get ( const char *code );
37 const char *lang_code_get2 ( const char *code, size_t len );
38 const lang_code_t *lang_code_get3 ( const char *code );
39 
40 const char *lang_code_preferred( void );
41 char *lang_code_user( const char *ucode );
42 
43 /* Split list of codes as per HTTP Language-Accept spec */
44 const char **lang_code_split ( const char *codes );
45 const lang_code_t **lang_code_split2 ( const char *codes );
46 
47 /* Efficient code lookup */
48 typedef struct lang_code_lookup_element {
49   RB_ENTRY(lang_code_lookup_element) link;
50   const lang_code_t *lang_code;
51 } lang_code_lookup_element_t;
52 
53 typedef RB_HEAD(lang_code_lookup, lang_code_lookup_element) lang_code_lookup_t;
54 
55 void lang_code_done( void );
56 
57 #endif /* __TVH_LANG_CODES_H__ */
58