[MPlayer-cvslog] r38300 - in trunk: Changelog Makefile configure help/help_create_po.pl

ib subversion at mplayerhq.hu
Thu Mar 4 16:43:07 EET 2021


Author: ib
Date: Thu Mar  4 16:43:07 2021
New Revision: 38300

Log:
Enable Native Language Support.

Add a configure option that allows specifying multiple languages for
messages (for the moment only for the GUI). By default, the option is
enabled for the GUI and disabled otherwise.

With option --disable-nls or when specifying only one language for
messages, nothing changes from the behavior so far, i.e. all texts
are compiled into the binary.

With option --enable-nls and specifying multiple languages, the English
texts are compiled into the binary and *.mo files are created for all
other languages.

For this, help_create_po.pl extracts the defined text constants from
the help/help_mp-*.h files and creates the necessary *.po intermediate
files.

Added:
   trunk/help/help_create_po.pl   (contents, props changed)
Modified:
   trunk/Changelog
   trunk/Makefile
   trunk/configure

Modified: trunk/Changelog
==============================================================================
--- trunk/Changelog	Mon Mar  1 16:17:49 2021	(r38299)
+++ trunk/Changelog	Thu Mar  4 16:43:07 2021	(r38300)
@@ -21,6 +21,9 @@ MPlayer
       e.g. Raspbian not using NEON by default.
       Can use --enable-runtime-cpudetection to restore the previous
       behaviour, though full runtime CPU detection is not supported.
+    * New configure option --enable-nls for Native Language Support at
+      runtime (for the moment only for the GUI and enabled by default
+      for it)
 
   1.4: "SubCounter" April 18, 2019
 

Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile	Mon Mar  1 16:17:49 2021	(r38299)
+++ trunk/Makefile	Thu Mar  4 16:43:07 2021	(r38300)
@@ -711,13 +711,15 @@ ADDSUFFIXES     = $(foreach suf,$(1),$(a
 ADD_ALL_DIRS    = $(call ADDSUFFIXES,$(1),$(ALL_DIRS))
 ADD_ALL_EXESUFS = $(1) $(call ADDSUFFIXES,$(EXESUFS_ALL),$(1))
 
+ALL_MSGS = $(foreach lang,$(filter-out $(firstword $(MSG_LANGS)),$(MSG_LANGS)),help/po/$(lang).mo)
+
 GUI_ICONSIZES = 16x16 22x22 24x24 32x32 48x48 256x256
 
 
 
 ###### generic rules #######
 
-all: $(ALL_PRG-yes)
+all: $(ALL_PRG-yes) $(ALL_MSGS)
 
 %.o: %.S
 	$(CC) $(CC_DEPFLAGS) $(CFLAGS) $(AS_C) $(AS_O) $<
@@ -774,6 +776,13 @@ helpcheck: $(addsuffix elpcheck,$(wildca
 help_mp.h: help/help_mp-en.h $(HELP_FILE)
 	help/help_create.sh $(HELP_FILE) $(CHARSET)
 
+help/po/%.po: help/help_mp-%.h help/help_mp-en.h
+	mkdir -p $(@D)
+	help/help_create_po.pl $< $@
+
+%.mo: %.po
+	msgfmt $< -o $@
+
 # rebuild version.h each time the working copy is updated
 version.h: version.sh $(wildcard .svn/entries .git/logs/HEAD)
 	./$< `$(CC) -dumpversion`
@@ -829,7 +838,7 @@ mpcommon.o osdep/mplayer-rc.o gui/dialog
 
 osdep/mplayer-rc.o: osdep/mplayer.exe.manifest
 
-gui/%: CFLAGS += -Wno-strict-prototypes
+gui/%: CFLAGS += -DLOCALEDIR=\"$(prefix)/share/locale\" -Wno-strict-prototypes
 
 loader/%: CFLAGS += -fno-omit-frame-pointer $(CFLAGS_NO_OMIT_LEAF_FRAME_POINTER)
 #loader/%: CFLAGS += -Ddbg_printf=__vprintf -DTRACE=__vprintf -DDETAILED_OUT
@@ -859,13 +868,14 @@ install-dirs:
 install-%: %$(EXESUF) install-dirs
 	$(INSTALL) -m 755 $(INSTALLSTRIP) $< $(BINDIR)
 
-install-gui: install-mplayer install-gui-icons
+install-gui: install-mplayer install-gui-icons install-gui-msg
 	-ln -sf mplayer$(EXESUF) $(BINDIR)/gmplayer$(EXESUF)
 	$(INSTALL) -d $(DATADIR)/skins $(prefix)/share/applications
 	$(INSTALL) -m 644 etc/mplayer.desktop $(prefix)/share/applications/
 
 install-gui-icons:    $(foreach size,$(GUI_ICONSIZES),install-gui-icon-$(size))
 install-gui-man:      $(foreach lang,$(MAN_LANGS),install-gui-man-$(lang))
+install-gui-msg:      $(foreach lang,$(filter-out $(firstword $(MSG_LANGS)),$(MSG_LANGS)),install-gui-msg-$(lang))
 install-mencoder-man: $(foreach lang,$(MAN_LANGS),install-mencoder-man-$(lang))
 install-mplayer-man:  $(foreach lang,$(MAN_LANGS),install-mplayer-man-$(lang))
 
@@ -890,6 +900,12 @@ install-gui-man-$(lang): install-mplayer
 	cd $(MANDIR)/$(lang)/man1/ && ln -sf mplayer.1 gmplayer.1
 endef
 
+define GUI_MSG_RULE
+install-gui-msg-$(lang): help/po/$(lang).mo
+	$(INSTALL) -d $(prefix)/share/locale/$(lang)/LC_MESSAGES
+	$(INSTALL) -m 644 help/po/$(lang).mo $(prefix)/share/locale/$(lang)/LC_MESSAGES/mplayer.mo
+endef
+
 define MENCODER_MAN_RULE
 install-mencoder-man-$(lang): install-mplayer-man-$(lang)
 	cd $(MANDIR)/$(lang)/man1 && ln -sf mplayer.1 mencoder.1
@@ -903,6 +919,7 @@ endef
 
 $(foreach size,$(GUI_ICONSIZES),$(eval $(GUI_ICON_RULE)))
 $(foreach lang,$(filter-out en,$(MAN_LANG_ALL)),$(eval $(GUI_MAN_RULE)))
+$(foreach lang,$(MSG_LANGS),$(eval $(GUI_MSG_RULE)))
 $(foreach lang,$(filter-out en,$(MAN_LANG_ALL)),$(eval $(MENCODER_MAN_RULE)))
 $(foreach lang,$(filter-out en,$(MAN_LANG_ALL)),$(eval $(MPLAYER_MAN_RULE)))
 
@@ -913,6 +930,7 @@ uninstall:
 	rm -f $(prefix)/share/applications/mplayer.desktop
 	rm -f $(MANDIR)/man1/mplayer.1 $(MANDIR)/man1/mencoder.1 $(MANDIR)/man1/gmplayer.1
 	rm -f $(foreach lang,$(MAN_LANGS),$(foreach man,mplayer.1 mencoder.1 gmplayer.1,$(MANDIR)/$(lang)/man1/$(man)))
+	rm -f $(foreach lang,$(MSG_LANGS),$(prefix)/share/locale/$(lang)/LC_MESSAGES/mplayer.mo)
 
 clean: testsclean toolsclean driversclean dhahelperclean
 	-$(MAKE) -C ffmpeg $@
@@ -922,7 +940,7 @@ clean: testsclean toolsclean driversclea
 	-rm -f $(VIDIX_PCI_FILES)
 	-rm -f $(call ADD_ALL_EXESUFS,codec-cfg cpuinfo)
 	-rm -f codecs.conf.h help_mp.h version.h
-	-rm -rf DOCS/tech/doxygen DOCS/HTML
+	-rm -rf DOCS/tech/doxygen DOCS/HTML help/po
 
 distclean: clean
 	-$(MAKE) -C ffmpeg $@
@@ -1113,6 +1131,8 @@ dhahelperclean:
 .PHONY: checkheaders *clean tests check_checksums fatetest helpcheck
 .PHONY: doc html-chunked* html-single* xmllint*
 
+.SECONDARY: $(patsubst %.mo,%.po,$(ALL_MSGS))
+
 # Disable suffix rules.  Most of the builtin rules are suffix rules,
 # so this saves some time on slow systems.
 .SUFFIXES:

Modified: trunk/configure
==============================================================================
--- trunk/configure	Mon Mar  1 16:17:49 2021	(r38299)
+++ trunk/configure	Thu Mar  4 16:43:07 2021	(r38300)
@@ -547,12 +547,15 @@ Language options:
   --language-man=lang    language to use for the man pages [en]
   --language-msg=lang    language to use for the messages and the GUI [en]
   --language=lang        default language to use [en]
+  --disable-nls          disable Native Language Support (GUI only) [autodetect]
 Specific options override --language. You can pass a list of languages separated
 by whitespace or commas instead of a single language. Nonexisting translations
 will be dropped from each list. All documentation and man page translations
-available in the list will be installed, for the messages the first available
-translation will be used. The value "all" will activate all translations. The
-LINGUAS environment variable is honored. In all cases the fallback is English.
+available in the list will be installed. This also applies to the messages,
+unless --disable-nls is specified or autodetected, in which case the first
+available translation will be used. The value "all" will activate all
+translations. The LINGUAS environment variable is honored. In all cases the
+fallback is English.
 Available values are: all $msg_lang_all
 
 Miscellaneous options:
@@ -823,6 +826,7 @@ _lircc=auto
 _apple_remote=auto
 _apple_ir=auto
 _gui=no
+_nls=auto
 _termcap=auto
 _termios=auto
 _3dfx=no
@@ -1303,6 +1307,8 @@ for ac_option do
   --disable-apple-ir)   _apple_ir=no    ;;
   --enable-gui)         _gui=yes        ;;
   --disable-gui)        _gui=no         ;;
+  --enable-nls)         _nls=yes        ;;
+  --disable-nls)        _nls=no         ;;
   --enable-termcap)     _termcap=yes    ;;
   --disable-termcap)    _termcap=no     ;;
   --enable-termios)     _termios=yes    ;;
@@ -3479,6 +3485,38 @@ fi
 echores "$_langinfo"
 
 
+echocheck "NLS"
+test "$_nls" = auto && _nls="$_gui"
+if test "$_nls" = yes -a "$_gui" = no; then
+  _nls=no
+  res_comment="disabled because --enable-gui not specified"
+fi
+if test "$_nls" = yes; then
+  def_nls='#define ENABLE_NLS 1'
+else
+  def_nls='#undef ENABLE_NLS'
+fi
+echores "$_nls"
+
+
+if test "$_nls" = yes; then
+  echocheck "Perl"
+  if test -z "$(which perl)"; then
+    echores "no"
+    echo "configure error: Perl not found; required for NLS"
+    exit 1
+  fi
+  echores "$_nls"
+  echocheck "msgfmt"
+  if test -z "$(which msgfmt)"; then
+    echores "no"
+    echo "configure error: msgfmt not found; required for NLS"
+    exit 1
+  fi
+  echores "$_nls"
+fi
+
+
 echocheck "language"
 # Set preferred languages, "all" uses English as main language.
 test -z "$language" && language=$LINGUAS
@@ -3491,10 +3529,12 @@ language_msg=$(echo $language_msg | tr ,
 
 test "$language_doc" = "all" && language_doc=$doc_lang_all
 test "$language_man" = "all" && language_man=$man_lang_all
-test "$language_msg" = "all" && language_msg=en
+if test "$language_msg" = "all"; then
+  test "$_nls" = yes && language_msg=$msg_lang_all || language_msg=en
+fi
 
 # Prune non-existing translations from language lists.
-# Set message translation to the first available language.
+# If NLS is disabled, set message translation to the first available language.
 # Fall back on English.
 for lang in $language_doc ; do
   test -d DOCS/xml/$lang && tmp_language_doc="$tmp_language_doc $lang"
@@ -3509,11 +3549,31 @@ language_man=$tmp_language_man
 test -z "$language_man" && language_man=en
 
 for lang in $language_msg ; do
-  test -f "help/help_mp-${lang}.h" && tmp_language_msg=$lang && break
+  if test -f "help/help_mp-${lang}.h"; then
+    if test "$_nls" = no; then
+      tmp_en=yes
+      tmp_language_msg=$lang
+      language_msg_main=$lang
+      break
+    else # _nls, and if more than one language then English is main and must come first
+      test -n "$tmp_language_msg" && language_msg_main=en
+      if test "$lang" = en; then
+        tmp_en=yes
+        tmp_language_msg="$lang $tmp_language_msg"
+      else
+        tmp_language_msg="$tmp_language_msg $lang"
+      fi
+      test -z "$language_msg_main" && language_msg_main=$lang
+    fi
+  fi
 done
 language_msg=$tmp_language_msg
-test -z "$language_msg" && language_msg=en
-_mp_help="help/help_mp-${language_msg}.h"
+test "$language_msg_main" = en -a -z "$tmp_en" && language_msg="en $language_msg"
+test -z "$language_msg" && language_msg=en && language_msg_main=en
+_mp_help="help/help_mp-${language_msg_main}.h"
+language_doc=$(echo $language_doc | tr -s " ")
+language_man=$(echo $language_man | tr -s " ")
+language_msg=$(echo $language_msg | tr -s " ")
 echores "messages: $language_msg - man pages: $language_man - documentation: $language_doc"
 
 
@@ -8602,6 +8662,7 @@ DOC_LANGS = $language_doc
 DOC_LANG_ALL = $doc_lang_all
 MAN_LANGS = $language_man
 MAN_LANG_ALL = $man_lang_all
+MSG_LANGS = $language_msg
 
 CATALOG = $catalog
 XMLLINT_COMMAND = xmllint --noout --noent --postvalid $catalog_opts
@@ -9172,6 +9233,7 @@ $def_debug
 $def_dynamic_plugins
 $def_fastmemcpy
 $def_menu
+$def_nls
 $def_runtime_cpudetection
 $def_sighandler
 $def_sortsub

Added: trunk/help/help_create_po.pl
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/help/help_create_po.pl	Thu Mar  4 16:43:07 2021	(r38300)
@@ -0,0 +1,84 @@
+#!/usr/bin/perl
+
+# create a po file from a help file
+#
+# $ARGV[0]: help file
+# $ARGV[1]: po file
+
+my %podefs;
+my %written;
+
+# read a help file
+
+sub read_help
+{
+  my ($file) = @_;
+  my ($lang) = ($file =~ /help\/help_mp-(.*).h/);
+
+  open(help, "< $file") or die "Cannot open $file";
+
+  while (my $line = <help>)
+  {
+    chomp $line;
+
+    if ($line =~ s/\\$//)
+    {
+      $line .= <help>;
+      redo unless eof(help);
+    }
+
+    next if ($line !~ /^\s*#define/);
+
+    my ($msgid, $msgstr) = ($line =~ /^\s*#define\s+(\w+)\s+(".*")/);
+
+    if (!$msgstr)
+    {
+      # defined by an other macro?
+      ($msgid, $msgstr) = ($line =~ /^\s*#define\s+(\w+)\s+(\w+)/);
+
+      next if (!$msgstr);
+
+      $msgstr = $podefs{$msgstr}{$lang};
+    }
+
+    $podefs{$msgid}{$lang} = $msgstr;
+  }
+
+  close(help);
+}
+
+read_help("help/help_mp-en.h");
+read_help($ARGV[0]);
+
+# create po file
+
+my ($lang) = ($ARGV[1] =~ /help\/po\/(.*).po/);
+open(po, "> $ARGV[1]") or die "Cannot open $ARGV[1]";
+
+print po "# DO NOT EDIT - this file is generated from $ARGV[0]\n";
+
+foreach my $id (keys %podefs)
+{
+  # for the moment only X11/GTK GUI strings
+  next if (substr($id, 0, 10) ne "MSGTR_GUI_");
+  next if (substr($id, 0, 15) eq "MSGTR_GUI_WIN32");
+
+  my $msgid = $podefs{$id}{"en"};
+  my $msgstr = $podefs{$id}{$lang} ? $podefs{$id}{$lang} : $msgid;
+
+  # avoid duplicates
+  next if ($written{$msgid}{$msgstr});
+
+  # no translation necessary
+  next if ($msgid eq $msgstr);
+
+  # different translations
+  die "$msgid has already been translated differently\n" if (keys %{$written{$msgid}});
+
+  print po "\nmsgid $msgid\n";
+  print po "msgstr $msgstr\n";
+
+  $written{$msgid}{$msgstr} = 1;
+}
+
+close(po);


More information about the MPlayer-cvslog mailing list