2005年1月8日星期六

vim-cream的菜单国际化支持

前几天给vim-cream的菜单做了一下国际化(i18n)支持,仿照vim自己的菜单i18n方法写的。
当然同时还做了简体中文的翻译(可到我的主页下载cream-menu-lang.zip)

前日才有机会发给cream的群组,今日收到cream的开发者回信说接受了,并且0.33版本将考虑更多的国际化支持(而不仅仅是菜单)。

以下是菜单国际化的支持补丁,但需要针对自己的语言编写菜单翻译脚本放到cream/lang目录下(参见我的中文翻译范例)

(Here is the patch for i18n of the menu. But you need to write the menu translation script for your own language. Check my translations for Simplified Chinese as an example)

--- cream-menu.vim.orig 2004-02-02 22:23:18.000000000 +0800
+++ cream-menu.vim 2004-12-02 11:52:18.000000000 +0800
@@ -21,6 +21,57 @@
" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
" 02111-1307, USA.
"
+function! Load_menu_translation()
+ " copied from vim's own menu.vim, with a little modification
+if exists("v:lang") || &langmenu != ""
+ " Try to find a menu translation file for the current language.
+ if &langmenu != ""
+ if &langmenu =~ "none"
+ let s:lang = ""
+ else
+ let s:lang = &langmenu
+ endif
+ else
+ let s:lang = v:lang
+ endif
+ " A language name must be at least two characters, don't accept "C"
+ if strlen(s:lang) > 1
+ " When the language does not include the charset add 'encoding'
+ if s:lang =~ '^aa|^aa_aa'
+ let s:lang = s:lang . '.' . &enc
+ endif
+
+ " We always use a lowercase name.
+ " Change "iso-8859" to "iso_8859" and "iso8859" to "iso_8859", some
+ " systems appear to use this.
+ " Change spaces to underscores.
+ let s:lang = substitute(tolower(s:lang), '.iso-', ".iso_", "")
+ let s:lang = substitute(s:lang, '.iso8859', ".iso_8859", "")
+ let s:lang = substitute(s:lang, " ", "_", "g")
+
" Remove "@euro", otherwise "LC_ALL=de_DE@euro gvim" will show English menus
+ let s:lang = substitute(s:lang, "@euro", "", "")
+ " Change "iso_8859-1" and "iso_8859-15" to "latin1", we always use the
+ " same menu file for them.
+ let s:lang = substitute(s:lang, 'iso_8859-15=', "latin1", "")
+ menutrans clear
+ exe "runtime! cream/lang/menu_" . s:lang . ".vim"
+
+ if !exists("did_menu_trans")
+ " There is no exact match, try matching with a wildcard added
+ " (e.g. find menu_de_de.iso_8859-1.vim if s:lang == de_DE).
+ let s:lang = substitute(s:lang, '.[^.]*', "", "")
+ exe "runtime! cream/lang/menu_" . s:lang . "*.vim"
+
+ if !exists("did_menu_trans") && strlen(LANG) > 1
+ " On windows locale names are complicated, try using LANG, it might
+ " have been set by set_init_1().
+ exe "runtime! cream/lang/menu_" . tolower(LANG) . "*.vim"
+ endif
+ endif
+ endif
+endif
+endfunction
+

function! Cream_menus()
" Creates each menu loader and calls it
@@ -60,5 +111,7 @@ function! Cream_menus()
let &cpo = cpo_save

endfunction
+source VIMRUNTIME/delmenu.vim
+call Load_menu_translation()
call Cream_menus()



Powered by ScribeFire.

没有评论: