project documentor using tools of gettext translate en to cn

来自中国的朋友,欢迎您在本版面使用中文讨论问题。请注意,如果您想得到不懂中文的人的帮助,请同时提供英文译文。
Help and discussions in Chinese.
Post Reply
liqi98136
Posts: 53
Joined: Sun Jan 17, 2010 11:37 pm

project documentor using tools of gettext translate en to cn

Post by liqi98136 »

project documentor using tools of gettext translate en to cn
利用gettext工具翻译项目documentor
主文件加

Documentor.ec

Code: Select all


#include <locale.h>
#include <libintl.h>
#include <stdlib.h> 
#define PACKAGE "documentor"
#define LOCALEDIR "locale"
#define _(STRING) gettext(STRING)  

....

Code: Select all

class Ecgettext
{
      Ecgettext()
      {
         char * lang = "cn";      //change language
         putenv("LANG=zh_CN");
         setlocale(LC_ALL, "zh_CN");
/*

        if ("cn" == lang) {
          putenv("LANG=zh_CN");
          setlocale(LC_ALL, "zh_CN");
      } else if ("en" == lang) {
          putenv("LANG=en_US");
          setlocale(LC_ALL, "en_US");
      } 
*/      
      bindtextdomain(PACKAGE, LOCALEDIR);
	   textdomain(PACKAGE);              
      bind_textdomain_codeset (PACKAGE, "utf-8");   ///newlines
       
      }
} 

Ecgettext eclanguage { }; 
附文件加
SettingsDialog.ec

Code: Select all

#include <locale.h>
#include <libintl.h>

#define _(STRING) gettext(STRING) 
将要翻译的字符串之间加 _( 和 )

然后利用poedit翻译生成po和mo文件,放到指定位置
Attachments
documentor.7z
(145.1 KiB) Downloaded 12208 times
Last edited by liqi98136 on Sun Aug 28, 2011 9:05 am, edited 1 time in total.
liqi98136
Posts: 53
Joined: Sun Jan 17, 2010 11:37 pm

Re: project documentor using tools of gettext translate en t

Post by liqi98136 »

问题question
1.为什么主界面不能翻译成中文呢?
mainform cannot be translated into chinese.
2.还有就是static char * 不让替换replace
show error:initializer element is not constant
提示错误:
eC Shared Library files (*.dll, *.so, *.dylib)
不让改为not modify
_(eC Shared Library files (*.dll, *.so, *.dylib))
liqi98136
Posts: 53
Joined: Sun Jan 17, 2010 11:37 pm

Re: project documentor using tools of gettext translate en t

Post by liqi98136 »

first question is done.第一个问题已经解决
与Ecgettext eclanguage { }; 定义和执行的位置有关,要放在最前面定义和执行就可以了.成功!
:D
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: project documentor using tools of gettext translate en t

Post by jerome »

Dear liqi,

I've just implemented some i18n support in the eC compiler!

Checkout this commit: https://github.com/ecere/sdk/commit/e78 ... 5d94ab3362
Please pull and rebuild the latest sources of the SDK.

The syntax for localizable strings is: $"string".

No other modification to the source code is required, all the initialization is automated by the symbol loader generator (ecs).

A .pot file is automatically generated inside the object directory (e.g. documentor/obj/debug.win32/documentor.pot).

I've cleaned up the localizable strings in your localized documentor source, ideally non-localizable strings should not have $ in front. I have then updated your .po file through Poedit, using the 'Update from pot file' feature. Only localizable strings remain. The resulting documentor.po has been committed to the documentor source.

As for changing environment variables for testing purposes, I have recently fixed the environment variables support in the IDE, so you can use that to set the language to Chinese, in Project / Settings / Workspace (e.g. LANGUAGE / zh_CN)

I'm hoping this will make it easy to integrate all your localization work of the Ecere SDK to our main source base on git :)

Thank you for your contributions!

All the best,

Jerome
liqi98136
Posts: 53
Joined: Sun Jan 17, 2010 11:37 pm

Re: project documentor using tools of gettext translate en t

Post by liqi98136 »

Great:-).
That is just my want.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: project documentor using tools of gettext translate en t

Post by jerome »

liqi,

The remaining problem is that 'locale' is a relative path, and so installed executables cannot find the localization data... I think the way forward will be to build our own gettext function within the Ecere library, that understands the .mo format. This way it can read files embedded within the executable/libraries files (project resources) and the localization data can be embedded. Also it removes the need for an extra requirement of the libintl library. I hope to implement this this coming week =)

Cheers,

Jerome
Post Reply