T2h_i18n.pm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. #+##############################################################################
  2. #
  3. # T2h_i18n.pm: Internationalization for texi2html
  4. #
  5. # Copyright (C) 1999, 2000, 2003, 2007, 2009 Free Software Foundation, Inc.
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License,
  10. # or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. # hashes were taken from texi2html.init in 2003.
  21. # Code originally written by Patrice Dumas.
  22. #
  23. #-##############################################################################
  24. # This requires perl version 5 or higher
  25. require 5.0;
  26. package Texi2HTML::I18n;
  27. use strict;
  28. use vars qw(
  29. @ISA
  30. @EXPORT
  31. );
  32. use Exporter;
  33. @ISA = qw(Exporter);
  34. @EXPORT = qw(pretty_date);
  35. my $language;
  36. my $i18n_dir = 'i18n'; # name of the directory containing the per language files
  37. #my $translation_file = 'translations.pl'; # file containing all the translations
  38. #my @known_languages = ('de', 'nl', 'es', 'no', 'pt', 'fr'); # The supported
  39. # languages
  40. ########################################################################
  41. # Language dependencies:
  42. # To add a new language extend the WORDS hash and create $T2H_<...>_WORDS hash
  43. # To redefine one word, simply do:
  44. # $T2h_i18n::T2H_LANGUAGES->{<language>}->{<word>} = 'whatever' in your personal init file.
  45. #
  46. # Those hashes are obsolete but retained here for reference
  47. my $T2H_WORDS_EN =
  48. {
  49. # titles of pages
  50. #'Table of Contents' => 'Table of Contents',
  51. #'Short Table of Contents' => 'Short Table of Contents',
  52. #'Index' => 'Index',
  53. #'About This Document' => 'About This Document',
  54. #'Footnotes' => 'Footnotes',
  55. #'See' => 'See',
  56. #'see' => 'see',
  57. #'section' => 'section',
  58. 'About This Document' => '',
  59. 'Table of Contents' => '',
  60. 'Short Table of Contents', => '',
  61. 'Index' => '',
  62. 'Footnotes' => '',
  63. 'See' => '',
  64. 'see' => '',
  65. 'section' => '',
  66. 'Top' => '',
  67. 'Untitled Document' => '',
  68. # If necessary, we could extend this as follows:
  69. # # text for buttons
  70. # 'Top_Button' => 'Top',
  71. # 'ToC_Button' => 'Contents',
  72. # 'Overview_Button' => 'Overview',
  73. # 'Index_button' => 'Index',
  74. # 'Back_Button' => 'Back',
  75. # 'FastBack_Button' => 'FastBack',
  76. # 'Prev_Button' => 'Prev',
  77. # 'Up_Button' => 'Up',
  78. # 'Next_Button' => 'Next',
  79. # 'Forward_Button' =>'Forward',
  80. # 'FastWorward_Button' => 'FastForward',
  81. # 'First_Button' => 'First',
  82. # 'Last_Button' => 'Last',
  83. # 'About_Button' => 'About'
  84. 'January' => '',
  85. 'February' => '',
  86. 'March' => '',
  87. 'April' => '',
  88. 'May' => '',
  89. 'June' => '',
  90. 'July' => '',
  91. 'August' => '',
  92. 'September' => '',
  93. 'October' => '',
  94. 'November' => '',
  95. 'December' => '',
  96. 'T2H_today' => '%s, %d %d',
  97. };
  98. my $T2H_WORDS_DE =
  99. {
  100. 'Table of Contents' => 'Inhaltsverzeichniss',
  101. 'Short Table of Contents' => 'Kurzes Inhaltsverzeichniss',
  102. 'Index' => 'Index',
  103. 'About This Document' => '&Uuml;ber dieses Dokument',
  104. 'Footnotes' => 'Fu&szlig;noten',
  105. 'See' => 'Siehe',
  106. 'see' => 'siehe',
  107. 'section' => 'Abschnitt',
  108. 'January' => 'Januar',
  109. 'February' => 'Februar',
  110. 'March' => 'M&auml;rz',
  111. 'April' => 'April',
  112. 'May' => 'Mai',
  113. 'June' => 'Juni',
  114. 'July' => 'Juli',
  115. 'August' => 'August',
  116. 'September' => 'September',
  117. 'October' => 'Oktober',
  118. 'November' => 'November',
  119. 'December' => 'Dezember',
  120. };
  121. my $T2H_WORDS_NL =
  122. {
  123. 'Table of Contents' => 'Inhoudsopgave',
  124. 'Short Table of Contents' => 'Korte inhoudsopgave',
  125. 'Index' => 'Index', #Not sure ;-)
  126. 'About This Document' => 'No translation available!', #No translation available!
  127. 'Footnotes' => 'No translation available!', #No translation available!
  128. 'See' => 'Zie',
  129. 'see' => 'zie',
  130. 'section' => 'sectie',
  131. 'January' => 'Januari',
  132. 'February' => 'Februari',
  133. 'March' => 'Maart',
  134. 'April' => 'April',
  135. 'May' => 'Mei',
  136. 'June' => 'Juni',
  137. 'July' => 'Juli',
  138. 'August' => 'Augustus',
  139. 'September' => 'September',
  140. 'October' => 'Oktober',
  141. 'November' => 'November',
  142. 'December' => 'December',
  143. };
  144. my $T2H_WORDS_ES =
  145. {
  146. 'Table of Contents' => '&iacute;ndice General',
  147. 'Short Table of Contents' => 'Resumen del Contenido',
  148. 'Index' => 'Index', #Not sure ;-)
  149. 'About This Document' => 'No translation available!', #No translation available!
  150. 'Footnotes' => 'Fu&szlig;noten',
  151. 'See' => 'V&eacute;ase',
  152. 'see' => 'v&eacute;ase',
  153. 'section' => 'secci&oacute;n',
  154. 'January' => 'enero',
  155. 'February' => 'febrero',
  156. 'March' => 'marzo',
  157. 'April' => 'abril',
  158. 'May' => 'mayo',
  159. 'June' => 'junio',
  160. 'July' => 'julio',
  161. 'August' => 'agosto',
  162. 'September' => 'septiembre',
  163. 'October' => 'octubre',
  164. 'November' => 'noviembre',
  165. 'December' => 'diciembre',
  166. };
  167. my $T2H_WORDS_NO =
  168. {
  169. 'Table of Contents' => 'Innholdsfortegnelse',
  170. 'Short Table of Contents' => 'Kort innholdsfortegnelse',
  171. 'Index' => 'Indeks', #Not sure ;-)
  172. 'About This Document' => 'No translation available!', #No translation available!
  173. 'Footnotes' => 'No translation available!',
  174. 'See' => 'Se',
  175. 'see' => 'se',
  176. 'section' => 'avsnitt',
  177. 'January' => 'januar',
  178. 'February' => 'februar',
  179. 'March' => 'mars',
  180. 'April' => 'april',
  181. 'May' => 'mai',
  182. 'June' => 'juni',
  183. 'July' => 'juli',
  184. 'August' => 'august',
  185. 'September' => 'september',
  186. 'October' => 'oktober',
  187. 'November' => 'november',
  188. 'December' => 'desember',
  189. };
  190. my $T2H_WORDS_PT =
  191. {
  192. 'Table of Contents' => 'Sum&aacute;rio',
  193. 'Short Table of Contents' => 'Breve Sum&aacute;rio',
  194. 'Index' => '&Iacute;ndice', #Not sure ;-)
  195. 'About This Document' => 'No translation available!', #No translation available!
  196. 'Footnotes' => 'No translation available!',
  197. 'See' => 'Veja',
  198. 'see' => 'veja',
  199. 'section' => 'Se&ccedil;&atilde;o',
  200. 'January' => 'Janeiro',
  201. 'February' => 'Fevereiro',
  202. 'March' => 'Mar&ccedil;o',
  203. 'April' => 'Abril',
  204. 'May' => 'Maio',
  205. 'June' => 'Junho',
  206. 'July' => 'Julho',
  207. 'August' => 'Agosto',
  208. 'September' => 'Setembro',
  209. 'October' => 'Outubro',
  210. 'November' => 'Novembro',
  211. 'December' => 'Dezembro',
  212. };
  213. my $T2H_WORDS_FR =
  214. {
  215. 'Table of Contents' => 'Table des mati&egrave;res',
  216. 'Short Table of Contents' => 'R&eacute;sum&eacute;e du contenu',
  217. 'Index' => 'Index',
  218. 'About This Document' => 'A propos de ce document',
  219. 'Footnotes' => 'Notes de bas de page',
  220. 'See' => 'Voir',
  221. 'see' => 'voir',
  222. 'section' => 'section',
  223. 'January' => 'Janvier',
  224. 'February' => 'F&eacute;vrier',
  225. 'March' => 'Mars',
  226. 'April' => 'Avril',
  227. 'May' => 'Mai',
  228. 'June' => 'Juin',
  229. 'July' => 'Juillet',
  230. 'August' => 'Ao&ucirc;t',
  231. 'September' => 'Septembre',
  232. 'October' => 'Octobre',
  233. 'November' => 'Novembre',
  234. 'December' => 'D&eacute;cembre',
  235. 'T2H_today' => 'le %2$d %1$s %3$d'
  236. };
  237. #$T2H_LANGUAGES =
  238. #{
  239. # 'en' => $T2H_WORDS_EN,
  240. # 'de' => $T2H_WORDS_DE,
  241. # 'nl' => $T2H_WORDS_NL,
  242. # 'es' => $T2H_WORDS_ES,
  243. # 'no' => $T2H_WORDS_NO,
  244. # 'pt' => $T2H_WORDS_PT,
  245. # 'fr' => $T2H_WORDS_FR,
  246. #};
  247. sub set_language($)
  248. {
  249. my $lang = shift;
  250. if (defined($lang) && exists($Texi2HTML::Config::LANGUAGES->{$lang}) && defined($Texi2HTML::Config::LANGUAGES->{$lang}))
  251. {
  252. $language = $lang;
  253. return 1;
  254. }
  255. else
  256. {
  257. return 0;
  258. }
  259. }
  260. sub get_language()
  261. {
  262. return $language;
  263. }
  264. my @MONTH_NAMES =
  265. (
  266. 'January', 'February', 'March', 'April', 'May',
  267. 'June', 'July', 'August', 'September', 'October',
  268. 'November', 'December'
  269. );
  270. # This is not used as code, but used to mark months as strings to be
  271. # translated
  272. if (0)
  273. {
  274. my @mark_month_for_translation = (
  275. gdt('January'),
  276. gdt('February'),
  277. gdt('March'),
  278. gdt('April'),
  279. gdt('May'),
  280. gdt('June'),
  281. gdt('July'),
  282. gdt('August'),
  283. gdt('September'),
  284. gdt('October'),
  285. gdt('November'),
  286. gdt('December')
  287. );
  288. }
  289. my $I = \&get_string;
  290. sub pretty_date($)
  291. {
  292. my $lang = shift;
  293. my($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
  294. ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
  295. $year += ($year < 70) ? 2000 : 1900;
  296. return main::gdt('{month} {day}, {year}', { 'month' => main::gdt($MONTH_NAMES[$mon]),
  297. 'day' => $mday, 'year' => $year });
  298. }
  299. my $error_no_en = 0;
  300. my %missing_strings;
  301. # arguments should already be converted
  302. sub get_string($;$$)
  303. {
  304. my $string = shift;
  305. my $arguments = shift;
  306. $arguments = undef if (!ref($arguments));
  307. my $state = shift;
  308. # if duplicate is passed, it means that we are in the text and so should
  309. # use the main state
  310. if (defined($state) and $state->{'duplicate'} and defined($Texi2HTML::THISDOC{'state'}))
  311. {
  312. $state = main::duplicate_formatting_state($Texi2HTML::THISDOC{'state'});
  313. }
  314. my $translated_string;
  315. my $T2H_LANGUAGES = $Texi2HTML::Config::LANGUAGES;
  316. if (! exists($T2H_LANGUAGES->{'en'}))
  317. {
  318. unless($error_no_en)
  319. {
  320. print STDERR "i18n: no LANGUAGES->{'en'} hash\n";
  321. $error_no_en = 1;
  322. }
  323. }
  324. else
  325. {
  326. unless (exists ($T2H_LANGUAGES->{'en'}->{$string}))
  327. {
  328. unless (exists($missing_strings{$string}))
  329. {
  330. #print STDERR "i18n: missing string $string\n";
  331. $missing_strings{$string} = 1;
  332. }
  333. }
  334. if (defined ($T2H_LANGUAGES->{$language}->{$string}) and
  335. ($T2H_LANGUAGES->{$language}->{$string} ne ''))
  336. {
  337. $translated_string = $T2H_LANGUAGES->{$language}->{$string};
  338. }
  339. elsif (defined ($T2H_LANGUAGES->{'en'}->{$string}) and
  340. ($T2H_LANGUAGES->{'en'}->{$string} ne ''))
  341. {
  342. $translated_string = $T2H_LANGUAGES->{'en'}->{$string};
  343. }
  344. else
  345. {
  346. $translated_string = $string;
  347. }
  348. }
  349. return main::substitute_line($translated_string, "translation", $state) unless (defined($arguments) or !keys(%$arguments));
  350. # taken from libintl perl, copyright Guido. sub __expand
  351. my %args = %$arguments;
  352. my $re = join '|', map { quotemeta $_ } keys %args;
  353. if ($state->{'keep_texi'})
  354. {
  355. $translated_string =~ s/\{($re)\}/defined $args{$1} ? $args{$1} : "{$1}"/ge;
  356. return $translated_string;
  357. }
  358. # if there are arguments, we must protect the {arg} constructs before
  359. # doing substitute_line. So there is a first pass here to change {arg}
  360. # to %@internal_translation_open_brace{}arg@internal_translation_close_brace{}
  361. $translated_string =~ s/\{($re)\}/\@internal_translation_open_brace\{\}$1\@internal_translation_close_brace\{\}/g;
  362. foreach my $map (\%Texi2HTML::Config::things_map, \%Texi2HTML::Config::pre_map, \%Texi2HTML::Config::texi_map, \%Texi2HTML::Config::simple_format_texi_map)
  363. {
  364. $map->{'internal_translation_open_brace'} = '{';
  365. $map->{'internal_translation_close_brace'} = '}';
  366. }
  367. $translated_string = main::substitute_line($translated_string, "translation", $state);
  368. $translated_string =~ s/\{($re)\}/defined $args{$1} ? $args{$1} : "{$1}"/ge;
  369. foreach my $map (\%Texi2HTML::Config::things_map, \%Texi2HTML::Config::pre_map, \%Texi2HTML::Config::texi_map, \%Texi2HTML::Config::simple_format_texi_map)
  370. {
  371. delete $map->{'internal_translation_open_brace'};
  372. delete $map->{'internal_translation_close_brace'};
  373. }
  374. return $translated_string;
  375. }
  376. 1;