]> git.sesse.net Git - vlc/blob - src/misc/darwin_specific.m
* New Hungarian translation contributed by 'DirectX' (Name under investigation)
[vlc] / src / misc / darwin_specific.m
1 /*****************************************************************************
2  * darwin_specific.m: Darwin specific features 
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: darwin_specific.m,v 1.16 2003/11/10 00:49:48 hartman Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Christophe Massiot <massiot@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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24 #include <string.h>                                              /* strdup() */
25 #include <stdlib.h>                                                /* free() */
26
27 #include <vlc/vlc.h>
28
29 #include <Cocoa/Cocoa.h>
30
31 #ifdef HAVE_LOCALE_H
32 #   include <locale.h>
33 #endif
34
35 /*****************************************************************************
36  * system_Init: fill in program path & retrieve language
37  *****************************************************************************/
38 static int FindLanguage( const char * psz_lang )
39 {
40     const char ** ppsz_parser;
41     const char * ppsz_all[] =
42     {
43         "German", "de",
44         "British", "en_GB",
45         "English", "en",
46         "Spanish", "es",
47         "French", "fr",
48         "Hungarian", "hu",
49         "Italian", "it",
50         "Japanese", "ja",
51         "Dutch", "nl",
52         "Norwegian", "no",
53         "Polish", "pl",
54         "Brazillian Portuguese", "pt_BR",
55         "Russian", "ru",
56         "Swedish", "sv",
57         NULL
58     };
59
60     for( ppsz_parser = ppsz_all ; ppsz_parser[0] ; ppsz_parser += 2 )
61     {
62         if( !strcmp( psz_lang, ppsz_parser[0] )
63              || !strcmp( psz_lang, ppsz_parser[1] ) )
64         {
65             setenv( "LANG", ppsz_parser[1], 1 );
66             return 1;
67         }
68     }
69
70     return 0;
71 }
72
73 void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
74 {
75     char i_dummy;
76     char *p_char, *p_oldchar = &i_dummy;
77
78     /* Get the full program path and name */
79     p_char = p_this->p_libvlc->psz_vlcpath = strdup( ppsz_argv[ 0 ] );
80
81     /* Remove trailing program name */
82     for( ; *p_char ; )
83     {
84         if( *p_char == '/' )
85         {
86             *p_oldchar = '/';
87             *p_char = '\0';
88             p_oldchar = p_char;
89         }
90
91         p_char++;
92     }
93
94     /* Check if $LANG is set. */
95     if ( (p_char = getenv("LANG")) == NULL )
96     {
97         NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
98
99         /* Retrieve user's preferences. */
100         NSUserDefaults * o_defs = [NSUserDefaults standardUserDefaults]; 
101         NSArray * o_languages = [o_defs objectForKey:@"AppleLanguages"]; 
102         NSEnumerator * o_enumerator = [o_languages objectEnumerator]; 
103         NSString * o_lang;
104
105         while ( (o_lang = [o_enumerator nextObject]) )
106         { 
107             const char * psz_string = [o_lang lossyCString];
108             if ( FindLanguage( psz_string ) )
109             {
110                 break;
111             }
112         }
113         
114         [o_pool release];
115     }
116 }
117
118 /*****************************************************************************
119  * system_Configure: check for system specific configuration options.
120  *****************************************************************************/
121 void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
122 {
123
124 }
125
126 /*****************************************************************************
127  * system_End: free the program path.
128  *****************************************************************************/
129 void system_End( vlc_t *p_this )
130 {
131     free( p_this->p_libvlc->psz_vlcpath );
132 }
133