]> git.sesse.net Git - vlc/blob - src/text/iso_lang.c
libvlccore: Rename iso_lang.h to vlc_iso_lang.h because we use VLC_EXPORT there,...
[vlc] / src / text / iso_lang.c
1 /*****************************************************************************
2  * iso_lang.c: function to decode language code (in dvd or a52 for instance).
3  *****************************************************************************
4  * Copyright (C) 1998-2004 the VideoLAN team
5  * $Id$
6  *
7  * Author: Stéphane Borel <stef@via.ecp.fr>
8  *         Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdio.h>
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <vlc/vlc.h>
35
36 #include "vlc_iso_lang.h"
37
38 /*****************************************************************************
39  * Local tables
40  *****************************************************************************/
41 #include "iso-639_def.h"
42
43 static const iso639_lang_t unknown_language =
44     { "Unknown", "Unknown", "??", "???", "???" };
45
46 /*****************************************************************************
47  * DecodeLanguage: gives the long language name from the two-letter
48  *                 ISO-639 code
49  *****************************************************************************/
50 const char * DecodeLanguage( uint16_t i_code )
51 {
52     const iso639_lang_t * p_lang;
53     uint8_t psz_code[3];
54
55     psz_code[0] = i_code >> 8;
56     psz_code[1] = i_code & 0xff;
57     psz_code[2] = '\0';
58
59     for( p_lang = p_languages; p_lang->psz_eng_name; p_lang++ )
60     {
61         if( !memcmp( p_lang->psz_iso639_1, psz_code, 2 ) )
62         {
63 # if 0
64             if( *p_lang->psz_native_name )
65             {
66                 return p_lang->psz_native_name;
67             }
68 #endif
69
70             return _( p_lang->psz_eng_name );
71         }
72     }
73
74     return _( "Unknown" );
75 }
76
77 const iso639_lang_t * GetLang_1( const char * psz_code )
78 {
79     const iso639_lang_t *p_lang;
80
81     for( p_lang = p_languages; p_lang->psz_eng_name; p_lang++ )
82         if( !strncmp( p_lang->psz_iso639_1, psz_code, 2 ) )
83             return p_lang;
84
85     return &unknown_language;
86 }
87
88 const iso639_lang_t * GetLang_2T( const char * psz_code )
89 {
90     const iso639_lang_t *p_lang;
91
92     for( p_lang = p_languages; p_lang->psz_eng_name; p_lang++ )
93         if( !strncmp( p_lang->psz_iso639_2T, psz_code, 3 ) )
94             return p_lang;
95
96     return &unknown_language;
97 }
98
99 const iso639_lang_t * GetLang_2B( const char * psz_code )
100 {
101     const iso639_lang_t *p_lang;
102
103     for( p_lang = p_languages; p_lang->psz_eng_name; p_lang++ )
104         if( !strncmp( p_lang->psz_iso639_2B, psz_code, 3 ) )
105             return p_lang;
106
107     return &unknown_language;
108 }
109