Skip to content

Commit

Permalink
add i18n support in applet
Browse files Browse the repository at this point in the history
  • Loading branch information
lins05 committed Oct 30, 2012
1 parent 7a2805a commit 265286f
Show file tree
Hide file tree
Showing 32 changed files with 1,086 additions and 290 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ configure
*/.deps
autom4te*
po/POTFILES
po/Makefile*
po/stamp-it
po/*.gmo
missing
mkinstalldirs
stamp-h1
Expand Down Expand Up @@ -109,3 +112,4 @@ web/dist/
tests/basic/conf2/misc/
tests/basic/conf2/seafile-data/


3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

if COMPILE_GUI
MAKE_GUI = gui
MAKE_PO = po
endif

if COMPILE_HTTPSERVER
Expand All @@ -22,7 +23,7 @@ else
endif

SUBDIRS = include data lib common daemon $(MAKE_GUI) $(MAKE_CLINET) $(MAKE_SERVER) \
app python tests web
app python tests web $(MAKE_PO)
DIST_SUBDIRS = include data lib common daemon gui daemon server tools monitor \
httpserver controller app python tests web

Expand Down
25 changes: 15 additions & 10 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -377,17 +377,21 @@ if test "$blinux" = true -a x${compile_client} = xyes; then
#PKG_CHECK_MODULES(LIBNAUTILUS_EXTENSION, [libnautilus-extension >= $LIBNAUTILUS_EXTENSION_REQUIRED])
#AC_SUBST(LIBNAUTILUS_EXTENSION_CFLAGS)
#AC_SUBST(LIBNAUTILUS_EXTENSION_LIBS)
fi

if test x${compile_client} = xyes; then

# For translation
#GETTEXT_PACKAGE=ccnet
#AC_SUBST(GETTEXT_PACKAGE)
#AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package.])
#AC_PROG_INTLTOOL([0.35])
#ALL_LINGUAS="en zh_cn"
#AM_GLIB_GNU_GETTEXT
#GLIB_DEFINE_LOCALEDIR(PACKAGE_LOCALE_DIR)
#PO=po
#AC_SUBST(PO)
m4_ifdef([IT_PROG_INTLTOOL],
[IT_PROG_INTLTOOL([0.35.0],[no-xml])],
[AC_MSG_ERROR("--enable-nls requires intltool to be installed.")])
AC_CHECK_HEADERS([libintl.h])
GETTEXT_PACKAGE=seafile
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE],["$GETTEXT_PACKAGE"],[Gettext package])
AM_GLIB_GNU_GETTEXT
seafilelocaledir='${prefix}/${DATADIRNAME}/locale'
AC_SUBST(seafilelocaledir)
AC_SUBST(INTLLIBS)
fi

if test x${compile_python} = xyes; then
Expand Down Expand Up @@ -469,6 +473,7 @@ AC_CONFIG_FILES(
tools/Makefile
tests/Makefile
tests/common-conf.sh
po/Makefile.in
)
# desktop/Makefile
# desktop/nautilus/Makefile
Expand Down
21 changes: 8 additions & 13 deletions gui/common/applet-common.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <glib/gi18n.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <getopt.h>
Expand All @@ -17,12 +18,6 @@
#include "seafile-applet.h"


#ifdef WIN32
#include "applet-po-gbk.h"
#else
#include "applet-po.h"
#endif

#ifdef __APPLE__
#include "../mac/seafile/seafile/platform.h"
#endif
Expand Down Expand Up @@ -162,9 +157,9 @@ collect_transfer_info (GString *msg, const char *info, char *repo_name)

gboolean is_upload = (strcmp(info, "upload") == 0);
char buf[4096];
snprintf (buf, sizeof(buf) , "%s %s, " S_SPEED " %d KB/s\n",
is_upload ? S_UPLOADING : S_DOWNLOADING,
repo_name, rate);
snprintf (buf, sizeof(buf) , "%s %s, %s %d KB/s\n",
is_upload ? _("Uploading") : _("Downloading"),
repo_name, _("Speed"), rate);
g_string_append (msg, buf);
}

Expand All @@ -190,7 +185,7 @@ handle_seafile_notification (char *type, char *content)
return;

} else if (strcmp(type, "repo.deleted_on_relay") == 0) {
snprintf (buf, sizeof(buf), "\"%s\" " S_REPO_DELETED_ON_RELAY, content);
snprintf (buf, sizeof(buf), "\"%s\" %s", content, _("is unsynced. \nReason: Deleted on server"));
trayicon_notify ("Seafile", buf);

} else if (strcmp(type, "sync.done") == 0) {
Expand All @@ -204,7 +199,7 @@ handle_seafile_notification (char *type, char *content)
char *repo_id = p + 1;

memcpy (applet->last_synced_repo, repo_id, strlen(repo_id) + 1);
snprintf (buf, sizeof(buf), "\"%s\" " S_REPO_SYNC_DONE, repo_name);
snprintf (buf, sizeof(buf), "\"%s\" %s", repo_name, _("is in sync"));
trayicon_notify ("Seafile", buf);

} else if (strcmp(type, "sync.access_denied") == 0) {
Expand All @@ -218,7 +213,7 @@ handle_seafile_notification (char *type, char *content)
char *repo_id = p + 1;

memcpy (applet->last_synced_repo, repo_id, strlen(repo_id) + 1);
snprintf (buf, sizeof(buf), "\"%s\" " S_REPO_ACCESS_DENIED, repo_name);
snprintf (buf, sizeof(buf), "\"%s\" %s", repo_name, _("failed to sync. \nAccess denied to service"));
trayicon_notify ("Seafile", buf);
} else if (strcmp(type, "sync.quota_full") == 0) {
/* format: <repo_name\trepo_id> */
Expand All @@ -231,7 +226,7 @@ handle_seafile_notification (char *type, char *content)
char *repo_id = p + 1;

memcpy (applet->last_synced_repo, repo_id, strlen(repo_id) + 1);
snprintf (buf, sizeof(buf), "\"%s\" " S_REPO_QUOTA_FULL, repo_name);
snprintf (buf, sizeof(buf), "\"%s\" %s", repo_name, _("failed to sync. Quota outage."));
trayicon_notify ("Seafile", buf);
}
#ifdef __APPLE__
Expand Down
59 changes: 0 additions & 59 deletions gui/common/applet-po.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,24 @@

#define S_WINDOW_NAME "seafile-applet"
#define S_WINDOW_TITLE "Seafile 初始化"
#define S_USERNAME_TOO_SHORT "用户名太短"
#define S_USERNAME_TOO_LONG "用户名太长"
#define S_USERNAME_INVALID "用户名只能由字母、数字和 ‘-’ 、 ‘_’ 组成"
#define S_CHOOSE_EXISTEDDIR "请选择配置文件所在的目录"
#define S_USERID_INVALID "错误的用户id"
#define S_PASSWD_NULL "密码不能为空"
#define S_PASSWD_TOO_SHORT "密码太短"
#define S_PASSWD_TOO_LONG "密码太长"
#define S_PASSWD_INVALID "密码不能包含空格"
#define S_PASSWD_DIFFERENT "两次输入的密码不一致"
#define S_CHOOSE_PROFILE "请选择一个配置文件"

#define S_UNKNOWN_ERR "未知错误"
#define S_WRONG_PASSWD "密码错误"
#define S_NAME_NULL "用户名不能为空"
#define S_PERMISSION_ERROR "权限不够"
#define S_CREATE_CONF_FAILED "创建配置文件错误"
#define S_CREATE_SEAFILE_CONF_FAILED "创建配置文件错误"
#define S_SELECT_CONFDIR "请选择一个目录用于放置配置目录"
#define S_DEFAULT_CONFDIR "由于未选择目录,使用默认配置文件目录"
#define S_SELECT_SEAFILEDIR "请选择一个磁盘用于放置Seafile元数据"
#define S_SEAFILE_STARTUP "Seafile 已启动"
#define S_SEAFILE_CLICK_HINT "点击图标即可打开管理页面"
#define S_LOGIN_FAILED "登录失败: "
#define S_CONN_SERVER_TIEMOUT "连接服务器超时"
#define S_CONNECTING_TO_SERVER "正在连接服务器"
#define S_VALIDATING_USER "正在验证用户名/密码"
#define S_INVALID_USER "错误的用户名/密码"
#define S_ENSURE_QUIT_INIT "Seafile 初始化仍未完成。确认要退出吗?"
#define S_LOGIN_SUCCESS "登录成功"
#define S_CREATING_CONF "正在生成配置文件,请稍候"
#define S_ENSURE_SKIP_LOGIN "确认跳过登录?"

#define S_PASSWD_EMPTY "密码不能为空"
#define S_PASSWD_TOO_SHORT "密码太短"
#define S_PASSWD_TOO_LONG "密码太长"
#define S_PASSWD_MISMATCH "两次输入的密码不一致"

#define S_DESC_EMPTY "描述不能为空"
#define S_DESC_TOO_SHORT "描述太短"
#define S_DESC_TOO_LONG "描述太长"
#define S_ENSURE_QUIT "确认退出?"

#define S_CREATING_REPO "正在创建资料库"
#define S_ERROR_NO_DAEMON "Seafile 未启动"
#define S_CREATE_REPO_SUCCESS "操作成功"
#define S_CREATE_REPO_FAILED "操作失败"

#define S_INTERNAL_ERROR "内部错误"
#define S_ENSURE_QUIT_CREATE "确认取消?"

#define S_BASE_SIZE_TOO_LARGE \
"原始目录 \"%s\" 过大(%d MB),最大允许的原始目录大小为 %d MB.\n\n 是否继续创建?"

#define S_FAILED_TO_CALC_DIR_SIZE "统计原始目录 [%s] 大小失败"

#define S_INIT_REPO_DLG_ALREADY_OPENED "请先关闭上一个创建 Seafile 资料库的对话框!"

#define S_REPO_CREATED "已变为资料库"
#define S_REPO_REMOVED "已解除同步"
#define S_REPO_SYNC_DONE "已同步"

#define S_SEAFILE_IN_TRANSFER "Seafile 正在传输数据"

#define S_NO_RELAY "您目前没有设置任何服务器,请到 Seafile 管理页面添加"

#define S_BOLD_FONT "宋体"

#define S_AVAILABLE "空闲"
#define S_AVAILABLE_UNKNOWN "空闲空间大小未知"

#define S_INIT_NICKNAME "设置昵称"
#define S_INIT_DISK "选择磁盘"
#define S_INIT_LOGIN "登录服务器"

#define S_REPO_SYNC_ERROR "同步时出错"
#define S_REPO_DELETED_ON_RELAY "已经被解除同步。\n原因:该目录已经在服务器上被删除"
Expand All @@ -88,9 +32,6 @@

#define S_SPEED "速度"

#define S_YOU_HAVE_NOT_LOGGED_IN "您尚未登录服务器"
#define S_NOT_ALLOWED_PATH "\"%s\" 是 Seafile 的工作目录,因此不能把 \"%s\" 变为资料库。\n你可以在该目录下创建一个子目录,再将这个子目录变为资料库"

#define S_SEAFILE_APPLET_ALREAD_RUNNING "Seafile 已经在运行中"

#define S_USER_MANUAL_FILENAME "Seafile使用帮助.txt"
Expand Down
4 changes: 3 additions & 1 deletion gui/gtk/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

AM_CFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\" \
-DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\" \
-DSEAFILE_LOCALE_DIR=\""$(seafilelocaledir)"\" \
-DGETTEXT_PACKAGE=\""$(GETTEXT_PACKAGE)"\" \
-I$(top_srcdir)/include \
-I$(top_srcdir)/lib \
-I$(top_builddir)/lib \
Expand All @@ -13,7 +15,7 @@ noinst_HEADERS = trayicon.h misc.h \
../common/ccnet-init.h \
../common/opendir-proc.h ../common/applet-rpc-service.h \
../common/applet-log.h ../common/rpc-wrapper.h \
../common/applet-po.h ../common/applet-common.h ../common/seafile-applet.h
../common/applet-common.h ../common/seafile-applet.h

bin_PROGRAMS = seafile-applet

Expand Down
18 changes: 1 addition & 17 deletions gui/gtk/init-ccnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Boston, MA 02111-1307, USA.
*/

#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -39,23 +40,6 @@ static GtkLabel *error_name_label;
static GtkLabel *name_label;
static GtkBuilder *builder;

static const char *error_str[] = {
"Unknown error",
"Permission error",
"Create config file failed",
"Create seafile config failed",
};

static const char *
error_code_to_str (const int code)
{
if (code <= 0 || code >= G_N_ELEMENTS(error_str))
return "Unknown error";

return error_str[code];
}


static void
show_warning (GtkWindow *window, const char *title, const char *warning_msg)
{
Expand Down
23 changes: 12 additions & 11 deletions gui/gtk/seafile-applet.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <signal.h>
#include <locale.h>

#include <glib/gi18n.h>
#include <gtk/gtk.h>

#include <ccnet.h>
Expand All @@ -17,7 +18,6 @@
#include "applet-common.h"
#include "trayicon.h"
#include "applet-log.h"
#include "applet-po.h"

#include "misc.h"

Expand Down Expand Up @@ -78,7 +78,10 @@ int ccnet_open_dir(const char *path)
{
char buf[4096];
snprintf (buf, 4096, "xdg-open '%s' &", path);
system (buf);
if (system (buf) < 0) {
applet_warning ("failed to exec: %s\n", buf);
return -1;
}
return 0;
}

Expand Down Expand Up @@ -146,19 +149,17 @@ seafile_applet_init (SeafileApplet *applet)
int
main (int argc, char **argv)
{
/* init i18n */
setlocale (LC_ALL, "");
bindtextdomain(GETTEXT_PACKAGE, SEAFILE_LOCALE_DIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);

if (count_process("seafile-applet") > 1) {
fprintf(stderr, "Seafile applet already running. I will quit.\n");
fprintf(stderr, _("Seafile is already running\n"));
exit(1);
}

#ifdef ENABLE_NLS
setlocale (LC_ALL, "");

bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset(PACKAGE, "UTF-8");
textdomain(PACKAGE);
#endif

gtk_init (&argc, &argv);
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default(),
PKGDATADIR);
Expand Down
4 changes: 2 additions & 2 deletions gui/gtk/trayicon.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdio.h>
#include <stdlib.h>

#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <libnotify/notify.h>

Expand All @@ -17,7 +18,6 @@
#include "applet-common.h"
#include "rpc-wrapper.h"
#include "applet-log.h"
#include "applet-po.h"

#ifdef HAVE_APP_INDICATOR
#include <libappindicator/app-indicator.h>
Expand Down Expand Up @@ -156,7 +156,7 @@ void reset_trayicon_and_tip(SeafileTrayIcon *icon)
} else {
if (applet->auto_sync_disabled) {
name = ICON_AUTO_SYNC_DISABLED;
tip = S_TIP_AUTO_SYNC_DISABLED;
tip = _("Auto sync is disabled");
} else {
name = ICON_STATUS_UP;
}
Expand Down
Loading

0 comments on commit 265286f

Please sign in to comment.