I'm sure this is the most missing feature of LyX ;-)

Astonishingly we currently don't support Vietnamese. Support for this is relatively easy, as there is a babel definition file available and inputenc's utf8 encoding covers all Vietnamese characters.

The only difference to other languages is that you have to load babel direcly 
with the language options:

\usepackage[bla,vietnam,blub]{babel}

and not

\documentclass[bla,vietnam,blub]{article}
\usepackage{babel}

The attached patch provides proper suport for Vietnamese. Even the PDF-bookmarks of exported documents will handle the double-accented Vietnamese characters.
Multi-language documents also work well, see the testcases in
http://bugzilla.lyx.org/show_bug.cgi?id=4245
when you are interested.

regards Uwe
Index: lib/languages
===================================================================
--- lib/languages	(revision 20720)
+++ lib/languages	(working copy)
@@ -66,4 +66,5 @@
 turkish     turkish	"Turkish"	false  iso8859-9  tr_TR	 ""
 ukrainian   ukrainian	"Ukrainian"	false  koi8-u     uk_UA	 ""
 usorbian    usorbian	"Upper Sorbian"	false  iso8859-2  hsb_DE	 ""
+vietnamese  vietnam	"Vietnamese"	false  utf8       vi_VN	 ""
 welsh       welsh	"Welsh"		false  iso8859-15 cy_GB	 ""
Index: lib/lyx2lyx/LyX.py
===================================================================
--- lib/lyx2lyx/LyX.py	(revision 20720)
+++ lib/lyx2lyx/LyX.py	(working copy)
@@ -80,7 +80,7 @@
                    ("1_3",     [221], minor_versions("1.3" , 7)),
                    ("1_4", range(222,246), minor_versions("1.4" , 5)),
                    ("1_5", range(246,277), minor_versions("1.5" , 1)),
-                   ("1_6", range(277,291), minor_versions("1.6" , 0))] # Uwe Stöhr, wrap table
+                   ("1_6", range(277,292), minor_versions("1.6" , 0))] # Uwe Stöhr, Vietnamese
 
 
 def formats_list():
Index: lib/lyx2lyx/lyx_1_6.py
===================================================================
--- lib/lyx2lyx/lyx_1_6.py	(revision 20720)
+++ lib/lyx2lyx/lyx_1_6.py	(working copy)
@@ -402,6 +402,24 @@
         i = i + 1
 
 
+def revert_vietnamese(document):
+    "Set language Vietnamese to English"
+    # Set document language from Vietnamese to English
+    i = 0
+    if document.language == "vietnamese":
+        document.language = "english"
+        i = find_token(document.header, "\\language", 0)
+        if i != -1:
+            document.header[i] = "\\language english"
+    j = 0
+    while True:
+        j = find_token(document.body, "\\lang vietnamese", j)
+        if j == -1:
+            return
+        document.body[j] = document.body[j].replace("\\lang vietnamese", "\\lang english")
+        j = j + 1
+
+
 ##
 # Conversion hub
 #
@@ -420,10 +438,12 @@
            [287, [convert_wrapfig_options]],
            [288, [convert_inset_command]],
            [289, [convert_latexcommand_index]],
-           [290, []]
+           [290, []],
+           [291, []]
           ]
 
-revert =  [[289, [revert_wraptable]],
+revert =  [[290, [revert_vietnamese]],
+           [289, [revert_wraptable]],
            [288, [revert_latexcommand_index]],
            [287, [revert_inset_command]],
            [286, [revert_wrapfig_options]],
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(revision 20721)
+++ src/Buffer.cpp	(working copy)
@@ -155,7 +155,7 @@
 
 namespace {
 
-int const LYX_FORMAT = 290; //Uwe Stöhr, wrap table
+int const LYX_FORMAT = 291; //Uwe Stöhr, Vietnamese
 
 } // namespace anon
 
Index: src/BufferParams.cpp
===================================================================
--- src/BufferParams.cpp	(revision 20720)
+++ src/BufferParams.cpp	(working copy)
@@ -54,6 +54,7 @@
 
 using std::count;
 using std::endl;
+using std::find;
 using std::string;
 using std::istringstream;
 using std::ostream;
@@ -899,7 +900,12 @@
 				language_options << ',';
 			language_options << language->babel();
 		}
-		if (lyxrc.language_global_options && !language_options.str().empty())
+		// when Vietnamese is used, babel must directly be loaded with the
+		// language options, not in the class options
+		int viet = language_options.str().find("vietnam");
+		// viet = string::npos when not found
+		if (lyxrc.language_global_options && !language_options.str().empty()
+			&& viet == string::npos)
 			clsoptions << language_options.str() << ',';
 	}
 
@@ -1548,7 +1554,11 @@
 	// other languages are used (lang_opts is then empty)
 	if (lang_opts.empty())
 		return string();
-	if (!lyxrc.language_global_options)
+	// when Vietnamese is used, babel must directly be loaded with the
+	// language options
+	int viet = lang_opts.find("vietnam");
+	// viet = string::npos when not found
+	if (!lyxrc.language_global_options || viet != string::npos)
 		return "\\usepackage[" + lang_opts + "]{babel}";
 	return lang_pack;
 }

Reply via email to