albfan / vim-breakpts

Set/View Vim breakpoints and browse functions visually
24 stars 2 forks source link

Configurable i18n support #14

Closed albfan closed 9 years ago

albfan commented 9 years ago

As breakpts relies on client/server messages and they are localized, actual solution do not allow an easy deploy of breakpts on "non english" "non spanish" vim installs

https://github.com/albfan/vim-breakpts/commit/03c494d5601aa4527134838afb6c05fdfec51bb2

Create an expandable dict with translations (or better solution, I would love to hear other options)

isaaczhang commented 9 years ago

Could we first run special vim commands to get localized messages, and then parse these messages to extract the localized "keywords" necessary for breakpts.vim? For example, the code below :exec "breakdel *" :exec "redir @a | breaklist | redir END" :exec "breakadd here" :exec "redir @b | breaklist | redir END" would put 'No breakpoints define' to register a and put '1 file {path to current script file} line {num}' to register b. With some regexp we can extract the keyword 'line'.

albfan commented 9 years ago

Great! I have check to change LANG env to test another languages but vim does not work that way. It is based on .po files

https://github.com/vim/vim/blob/fc53ec1e9aac682a8524698240ed2bb6f7b0e300/src/po/es.po#L1348

so we only need to check vim sources and grep for desired messages (sorry for the unknow characters) to generate a i18n dict of l10n dict

$ ag 'msgid "Breakpoint in' -A1
src/po/pl.po
826:msgid "Breakpoint in \"%s%s\" line %ld"
827-msgstr "Punkt kontrolny w \"%s%s\" wiersz %ld"
src/po/uk.cp1251.po
876:msgid "Breakpoint in \"%s%s\" line %ld"
877-msgstr "����� ������� � �%s%s� ����� %ld"
src/po/ja.euc-jp.po
1106:msgid "Breakpoint in \"%s%s\" line %ld"
1107-msgstr "�֥졼���ݥ����� \"%s%s\" �� %ld"
src/po/nl.po
1053:msgid "Breakpoint in \"%s%s\" line %ld"
1054-msgstr "'Breakpoint' in \"%s%s\" regel %ld"
src/po/vi.po
500:msgid "Breakpoint in \"%s%s\" line %ld"
501-msgstr "Điểm dừng trên \"%s%s\" dòng %ld"
src/po/zh_CN.UTF-8.po
962:msgid "Breakpoint in \"%s%s\" line %ld"
963-msgstr "断点 \"%s%s\" 第 %ld 行"
src/po/pt_BR.po
758:msgid "Breakpoint in \"%s%s\" line %ld"
759-msgstr "Ponto de interrup��o em \"%s%s\", linha %ld"
src/po/sk.cp1250.po
911:msgid "Breakpoint in \"%s%s\" line %ld"
912-msgstr "Bod preru�enia v \"%s%s\" na riadku %ld"
src/po/ru.cp1251.po
1136:msgid "Breakpoint in \"%s%s\" line %ld"
1137-msgstr "����� ��������� � \"%s%s\" ���. %ld"
src/po/no.po
1000:msgid "Breakpoint in \"%s%s\" line %ld"
1001-msgstr "Stoppunkt i \"%s%s\" linje %ld"
src/po/ru.po
1136:msgid "Breakpoint in \"%s%s\" line %ld"
1137-msgstr "Точка остановки в \"%s%s\" стр. %ld"
src/po/de.po
949:msgid "Breakpoint in \"%s%s\" line %ld"
950-msgstr "Haltepunkt in \"%s%s\" Zeile %ld"
src/po/ja.po
1106:msgid "Breakpoint in \"%s%s\" line %ld"
1107-msgstr "ブレークポイント \"%s%s\" 行 %ld"
src/po/sk.po
911:msgid "Breakpoint in \"%s%s\" line %ld"
912-msgstr "Bod preru�enia v \"%s%s\" na riadku %ld"
src/po/pl.UTF-8.po
826:msgid "Breakpoint in \"%s%s\" line %ld"
827-msgstr "Punkt kontrolny w \"%s%s\" wiersz %ld"
src/po/fr.po
1336:msgid "Breakpoint in \"%s%s\" line %ld"
1337-msgstr "Point d'arr�t dans %s%s ligne %ld"
src/po/nb.po
1000:msgid "Breakpoint in \"%s%s\" line %ld"
1001-msgstr "Stoppunkt i \"%s%s\" linje %ld"
src/po/zh_CN.cp936.po
963:msgid "Breakpoint in \"%s%s\" line %ld"
964-msgstr "�ϵ� \"%s%s\" �� %ld ��"
src/po/it.po
1139:msgid "Breakpoint in \"%s%s\" line %ld"
1140-msgstr "Pausa in \"%s%s\" riga %ld"
src/po/sv.po
720:msgid "Breakpoint in \"%s%s\" line %ld"
721-msgstr "Brytpunkt i \"%s%s\" rad %ld"
src/po/fi.po
793:msgid "Breakpoint in \"%s%s\" line %ld"
794-msgstr "Katkaisukohta %s%s rivill� %ld"
src/po/af.po
517:msgid "Breakpoint in \"%s%s\" line %ld"
518-msgstr "Inspeksiepunt in \"%s%s\" re�l %ld"
src/po/zh_CN.po
963:msgid "Breakpoint in \"%s%s\" line %ld"
964-msgstr "�ϵ� \"%s%s\" �� %ld ��"
src/po/ko.po
1054:msgid "Breakpoint in \"%s%s\" line %ld"
1055-msgstr "������: \"%s%s\" %ld ��"
src/po/pl.cp1250.po
826:msgid "Breakpoint in \"%s%s\" line %ld"
827-msgstr "Punkt kontrolny w \"%s%s\" wiersz %ld"
src/po/ca.po
736:msgid "Breakpoint in \"%s%s\" line %ld"
737-msgstr "Punt de ruptura a \"%s%s\" l�nia %ld"
src/po/zh_TW.UTF-8.po
788:msgid "Breakpoint in \"%s%s\" line %ld"
789-msgstr "\"%s%s\" 中斷點: 第 %ld 行 "
src/po/es.po
1348:msgid "Breakpoint in \"%s%s\" line %ld"
1349-msgstr "\"Breakpoint\" en \"%s%s\" línea %ld"
src/po/cs.cp1250.po
693:msgid "Breakpoint in \"%s%s\" line %ld"
694-msgstr "Bod p�eru�en� v \"%s%s\" na ��dku %ld"
src/po/ko.UTF-8.po
1054:msgid "Breakpoint in \"%s%s\" line %ld"
1055-msgstr "중지점: \"%s%s\" %ld 줄"
src/po/uk.po
876:msgid "Breakpoint in \"%s%s\" line %ld"
877-msgstr "Точка зупинки в «%s%s» рядок %ld"
src/po/ja.sjis.po
1106:msgid "Breakpoint in \"%s%s\" line %ld"
1107-msgstr "�u���[�N�|�C���g \"%s%s\" �s %ld"
src/po/zh_TW.po
781:msgid "Breakpoint in \"%s%s\" line %ld"
782-msgstr "\"%s%s\" ���_�I: �� %ld �� "
src/po/ga.po
1139:msgid "Breakpoint in \"%s%s\" line %ld"
1140-msgstr "Brisphointe i \"%s%s\" l�ne %ld"
src/po/cs.po
693:msgid "Breakpoint in \"%s%s\" line %ld"
694-msgstr "Bod p�eru�en� v \"%s%s\" na ��dku %ld"
src/po/eo.po
1152:msgid "Breakpoint in \"%s%s\" line %ld"
1153-msgstr "Kontrolpunkto en \"%s%s\" linio %ld"

Main idea would be to create something like

lect i18nDict = {
   'es': {
      'breaklist_message': "línea",
      ...
   }, 
   'en':{
      'breaklist_message': "line",
      ...
   } 
}
"use with 
i18nDict.$LANG.breaklist_message
...
isaaczhang commented 9 years ago

I've got another idea.

Instead of generating a dic, we can parse out the desired token phrases and put them into s:str_line and s:str_in_line for the current $LANG every time BreakPts is invoked.

I've pushed the modification to isaaczhang/BreakPts and tested it for $LANG 'en' and $LANG 'zh_CN'. You could check it for your env and merge the commit to your project if it works.

albfan commented 9 years ago

I will check as soon as possible. Great part of avoiding PR is the fast forward merge. Anyway if there's something to improve we can open one.

albfan commented 9 years ago

Seems to work. But take this in consideration:

http://vimdoc.sourceforge.net/htmldoc/mlang.html#multi-lang

check if (in vim)

:language zh

works for you (not for me) so any try with chinese (or languagues I don't managed) don't fall back to english locale.

I would prefer to isolate these into a new function breakpts#GetLocalizedStrings. The regexp would need to change a bit to find that function instead of BrowserMain, but apart from that I will merge as soon as you refactor it.

albfan commented 9 years ago

I finally managed to activate chinese locale

https://wiki.archlinux.org/index.php/Locale

On arch linux is just uncomment a line on /etc/locale.gen and launch

$ sudo locale.gen

$ locale -a
C
es_ES.utf8
POSIX
zh_CN.utf8

I have installed also recommended chinese fonts

https://wiki.archlinux.org/index.php/Fonts#Chinese.2C_Japanese.2C_Korean.2C_Vietnamese

After that I'm seeing messages in chinese.

$ export LANG=zh_CN.UTF-8
$ vim
:breaklist
没有定义断点    #that should mean no breakpoints
:language C #I have no en_US.UTF-8
:breakpoints
No breakpoints defined

I will do a thorough test tomorrow.

As I mention before, this seems to need some review, can you rebase your changes on top of this repo and open a pull request?

albfan commented 9 years ago

Chinese is funny:

第 = Article
行 = OK
function foobar,第 45 行 = function foobar, line 45

It would be nice to cache that str_line to avoid keep doing it all the time BreakPts is accesed. but that's not really important.

Working on chinese, spanish and english for me is enough. Please rebase and open PR to cleanup code (see comments on your commit) and finish merge

isaaczhang commented 9 years ago

A single Chinese word may has many means. Under this circumstance, 第 = -th (ordinal suffix) 行 = Line function foobar,第 45 行 = function foobar, 45th line :)