Skip to content

Commit

Permalink
Added multilanguage support with automatic detection of OS language
Browse files Browse the repository at this point in the history
  • Loading branch information
joemck committed Nov 21, 2017
1 parent 41c1f97 commit 9872c9a
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 97 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ WINDRES = windres
LD = gcc
RM = rm -f

CFLAGS += -Os
LDFLAGS += -lcomdlg32 -mwindows
CFLAGS += -Os -DUNICODE -D_UNICODE -DWINVER=0x0501 -D_WIN32_WINNT=0x0501
LDFLAGS += -lcomdlg32 -mwindows -municode

TARGET = ExtractMotionPhotos.exe
OBJ = main.o res.o
HEADERS =
OBJ = main.o lang.o res.o
HEADERS = lang.h lang_en-us.h lang_zh-tw.h
RES_O = res.o
RES_RC = res.rc
RES_DEPENDS = icon_multires.ico
Expand Down
52 changes: 52 additions & 0 deletions lang.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Language base - this contains the language detector function */

#include <windows.h>
#include <wchar.h>
#include <string.h>
#include "lang.h"

enum {
LANG_EN_US = 0,
LANG_ZH_TW = 1,
};

int lang_index;
const WCHAR *lang_tbl[][N_ELEMS] =
{
//ID 0: English
{
#include "lang_en-us.h"
},
//ID 1: Chinese (Traditional)
{
#include "lang_zh-tw.h"
},
};

void detectLanguage(int argc, WCHAR **argv) {
LANGID lang;
int offs;

//append "_en" to exe name to force English
offs = wcslen(argv[0]) - 7;
if(0 == _wcsicmp(argv[0]+offs, L"_en.exe"))
lang_index = LANG_EN_US;

//append "_zh" to exe name to force Chinese
else if(0 == _wcsicmp(argv[0]+offs, L"_zh.exe"))
lang_index = LANG_ZH_TW;

//otherwise, follow the system preferred language settings
else {
lang = GetUserDefaultUILanguage();
if((lang & 0x0ff) == 0x04)
//xx04 => some form of Chinese; we only have 1 Chinese translation, so use that for all Chinese locales
lang_index = LANG_ZH_TW;
else
lang_index = LANG_EN_US;
}
}

const WCHAR* TR(int id) {
return lang_tbl[lang_index][id];
}
35 changes: 35 additions & 0 deletions lang.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Language base - this defines language structures and then includes a special
* file for each language.
*/

#ifndef __LANG_H_
#define __LANG_H_

enum lang_elems {
USAGE,
APP_TITLE,
FILETYPES,
OPEN_TITLEBAR,
SKIP_LONG_PATH,
ERROR_TITLEBAR,
ERROR_TOO_MANY_FILES_NUM,
ERROR_TOO_MANY_FILES_UNK,
PHOTO_APPEND,
VIDEO_APPEND,
ERROR_OUT_OF_MEMORY,
SKIP_READ_ERROR,
SKIP_WRITE_ERROR,
SUCCESS_MSG,
SUCCESS_MSG_SKIP,
SUCCESS_TITLEBAR,
FAILURE_TITLEBAR,
N_ELEMS
};

extern int lang_index;
extern const WCHAR *lang_tbl[2][N_ELEMS];

void detectLanguage(int argc, WCHAR **argv);
const WCHAR* TR(int id);

#endif /* __LANG_H_ */
62 changes: 62 additions & 0 deletions lang_en-us.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//Language file for English -- just the strings themselves; position determines which ID goes with them

/* USAGE */
L"You can use this program 3 different ways:\r\n"
L"\r\n"
L"GUI USE: Just run it. You'll get an file-open dialog where you can open .jpg files. Use ctrl or shift or drag to select more than one.\r\n"
L"\r\n"
L"DRAG & DROP USE: Drag one or more motion photos onto the icon for this exe.\r\n"
L"\r\n"
L"COMMAND LINE USE: Run this program with one or more motion photo file names as arguments. Remember to use \"quotes\" if there are spaces in the names.\r\n"
L"\r\n"
L"Any way you run it, the original files will not be modified. The extracted photo and video will be stored in *_photo.jpg and *_video.mp4 where * is the name of the original file, minus the .jpg extension.\r\n"
L"\r\n"
L"Coded by Chupi383. All credit for the method goes to goofwear at the XDA forums. I've just ported their .bat file to plain C and Win32."
,
/* APP_TITLE */
L"Samsung Motion Photo Batch Extractor"
,
/* FILETYPES */
L"Motion Photos (*.jpg)\0*.JPG\0All Files\0*.*\0\0"
,
/* OPEN_TITLEBAR */
L"Open some Samsung Motion Photos"
,
/* SKIP_LONG_PATH */
L"Skipping too-long path:\r\n%s%s%s"
,
/* ERROR_TITLEBAR */
L"Error"
,
/* ERROR_TOO_MANY_FILES_NUM */
L"You've selected too many files. I can only do up to %d at a time."
,
/* ERROR_TOO_MANY_FILES_UNK */
L"You've selected too many files. Try selecting fewer files and process them in bunches."
,
/* PHOTO_APPEND */
L"_photo.jpg"
,
/* VIDEO_APPEND */
L"_video.mp4"
,
/* ERROR_OUT_OF_MEMORY */
L"Can't allocate RAM to read %ld bytes from %s"
,
/* SKIP_READ_ERROR */
L"Skipping due to read error:\r\n%s"
,
/* SKIP_WRITE_ERROR */
L"Can't write to %s"
,
/* SUCCESS_MSG */
L"Finished extracting Motion Photos\r\n Photos extracted: %d\r\n Videos extracted: %d"
,
/* SUCCESS_MSG_SKIP */
L"\r\n%d files were skipped because they weren't Motion Photos"
,
/* SUCCESS_TITLEBAR */
L"Success"
,
/* FAILURE_TITLEBAR */
L"Failure"
62 changes: 62 additions & 0 deletions lang_zh-tw.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//Language file for Chinese (Traditional) -- just the strings themselves; position determines which ID goes with them

/* USAGE */
L"有三種方式可以使用本軟體:\r\n"
L"\r\n"
L"一:點開軟體後選擇你要轉存的照片,你可以使用Ctrl或是Shift來多選檔案。\r\n"
L"\r\n"
L"二:把你要的照片拖移到本軟體的icon上也能轉存!\r\n"
L"\r\n"
L"三:你也能使用Command Line來處理喔! (記得用\"quotes\"取代空格)\r\n"
L"\r\n"
L"請放心:無論你怎麼做,原始檔案都不會被修改。轉存成功的檔案將會存在原始檔案位置,並新增為 *_photo.jpg 和 *_video.mp4。\r\n"
L"\r\n"
L"GUI軟體由Chupi383撰寫,軟體內核由XDA forums的goofwear撰寫,Andylain翻譯正體中文,詳細中文使用教學請上「安迪連碎碎念」。"
,
/* APP_TITLE */
L"三星動態相片批次轉存工具"
,
/* FILETYPES */
L"動態相片 (*.jpg)\0*.JPG\0所有檔案 (*.*)\0*.*\0\0"
,
/* OPEN_TITLEBAR */
L"開啟一些動態相片"
,
/* SKIP_LONG_PATH */
L"已忽略太長的路徑:\r\n%s%s%s"
,
/* ERROR_TITLEBAR */
L"發生錯誤"
,
/* ERROR_TOO_MANY_FILES_NUM */
L"你一次選太多檔案了。我一次只能處理一 %d 個檔案。"
,
/* ERROR_TOO_MANY_FILES_UNK */
L"你一次選太多檔案了。嘗試選少一點檔案吧!"
,
/* PHOTO_APPEND */
L"_photo.jpg"
,
/* VIDEO_APPEND */
L"_video.mp4"
,
/* ERROR_OUT_OF_MEMORY */
L"記憶體定位錯誤,無法讀取 %ld bytes 上的 %s 檔案,有可能電腦的RAM不足。"
,
/* SKIP_READ_ERROR */
L"由於讀取錯誤,已跳過處理:\r\n%s"
,
/* SKIP_WRITE_ERROR */
L"無法寫入 %s 可能目的地已滿或是為唯讀。"
,
/* SUCCESS_MSG */
L"動態相片轉存結果:\r\n 有 %d 張照片輸出成功!\r\n 有 %d 個影片輸出成功!"
,
/* SUCCESS_MSG_SKIP */
L"\r\n%d 個檔案被跳過了,因為它們不是三星動態相片。"
,
/* SUCCESS_TITLEBAR */
L"轉存成功"
,
/* FAILURE_TITLEBAR */
L"轉存失敗"
Loading

0 comments on commit 9872c9a

Please sign in to comment.