1212
1313from je_editor .git_client .git_action import GitService
1414from je_editor .utils .logging .loggin_instance import jeditor_logger
15+ from je_editor .utils .multi_language .multi_language_wrapper import language_wrapper
1516
1617# UI 常數 / UI constants
1718_CLONE_REPO_LABEL = "Clone Repo"
1819_REPO_STATUS_DEFAULT = "Status: -"
1920
2021
22+ def _text (key : str ) -> str :
23+ """
24+ 取得翻譯後的文字
25+ The translated text for a key.
26+
27+ 這個面板的字串原本是寫死的英文,但語言檔裡一直有對應的翻譯沒被用到。
28+ This panel's strings used to be hard-coded English while the translations for
29+ them sat unused in the language files.
30+
31+ :param key: 語言鍵 / the language key
32+ :return: 翻譯後的文字 / the translated text
33+ """
34+ return language_wrapper .language_word_dict .get (key , key )
35+
36+
37+ def _word (key : str ) -> QPushButton :
38+ """建立一個帶翻譯文字的按鈕 / A button labelled with a translated key."""
39+ return QPushButton (_text (key ))
40+
41+
42+ def _label (key : str ) -> QLabel :
43+ """建立一個帶翻譯文字的標籤 / A label showing a translated key."""
44+ return QLabel (_text (key ))
45+
46+
2147class _GitWorker (QObject ):
2248 """背景執行 Git 操作的 Worker / Background worker for Git operations"""
2349 finished = Signal (object ) # result
@@ -88,16 +114,16 @@ def _run_git_in_background(self, func: Callable, on_done: Callable | None = None
88114 def _init_ui (self ) -> None :
89115 # === Top controls / 上方控制區 ===
90116 self .repo_path_label = QLabel ("Repository: (none)" )
91- self .open_repo_button = QPushButton ( "Open Repo " )
117+ self .open_repo_button = _word ( "btn_open_repo " )
92118 self .branch_selector = QComboBox ()
93- self .checkout_button = QPushButton ( "Checkout " )
119+ self .checkout_button = _word ( "btn_checkout " )
94120 self .clone_repo_button = QPushButton (_CLONE_REPO_LABEL )
95121 self .repo_status_label = QLabel (_REPO_STATUS_DEFAULT )
96122 self .commit_status_label = QLabel ("Unpushed commits: ..." )
97123
98124 top = QHBoxLayout ()
99125 top .addWidget (self .repo_path_label , 1 )
100- top .addWidget (QLabel ( "Branch: " ))
126+ top .addWidget (_label ( "label_branch " ))
101127 top .addWidget (self .branch_selector , 1 )
102128 top .addWidget (self .checkout_button )
103129 top .addWidget (self .open_repo_button )
@@ -134,21 +160,21 @@ def _init_ui(self) -> None:
134160
135161 # === Bottom: staging and commit controls / 下方:stage 與 commit 控制 ===
136162 self .commit_message_input = QLineEdit ()
137- self .commit_message_input .setPlaceholderText ("Commit message..." )
138- self .stage_selected_button = QPushButton ( "Stage Selected " )
139- self .unstage_selected_button = QPushButton ( "Unstage Selected " )
140- self .stage_all_button = QPushButton ( "Stage All " )
141- self .commit_button = QPushButton ( "Commit " )
142- self .unstage_all_button = QPushButton ( "Unstage All " )
143- self .track_all_untracked_button = QPushButton ( "Track All Untracked " )
144- self .git_push_button = QPushButton ( "Push " )
163+ self .commit_message_input .setPlaceholderText (_text ( "placeholder_commit_message" ) )
164+ self .stage_selected_button = _word ( "btn_stage_selected " )
165+ self .unstage_selected_button = _word ( "btn_unstage_selected " )
166+ self .stage_all_button = _word ( "btn_stage_all " )
167+ self .commit_button = _word ( "btn_commit " )
168+ self .unstage_all_button = _word ( "btn_unstage_all " )
169+ self .track_all_untracked_button = _word ( "btn_track_all_untracked " )
170+ self .git_push_button = _word ( "btn_push " )
145171 # 收起手邊的修改與解決合併衝突 / Putting work down, and settling a merge
146- self .stash_button = QPushButton ( "Stash " )
147- self .stash_pop_button = QPushButton ( "Pop Stash " )
148- self .resolve_button = QPushButton ( "Resolve Conflict " )
172+ self .stash_button = _word ( "btn_stash " )
173+ self .stash_pop_button = _word ( "btn_stash_pop " )
174+ self .resolve_button = _word ( "btn_resolve_conflict " )
149175
150176 bottom = QHBoxLayout ()
151- bottom .addWidget (QLabel ( "Message: " ))
177+ bottom .addWidget (_label ( "label_message " ))
152178 bottom .addWidget (self .commit_message_input , 1 )
153179 bottom .addWidget (self .stage_selected_button )
154180 bottom .addWidget (self .unstage_selected_button )
@@ -738,7 +764,7 @@ def on_stash_changes(self) -> None:
738764 try :
739765 service .stash_save (message )
740766 except GitCommandError as error :
741- QMessageBox .critical (self , "Error" , f"Could not stash :\n { error } " )
767+ QMessageBox .critical (self , "Error" , f"{ _text ( 'err_stash' ) } :\n { error } " )
742768 return
743769 self .commit_message_input .clear ()
744770 self ._refresh_change_list ()
@@ -757,16 +783,18 @@ def on_pop_stash(self) -> None:
757783 return
758784 stashes = service .stash_list ()
759785 if not stashes :
760- QMessageBox .information (self , "Stash" , "There is nothing stashed." )
786+ QMessageBox .information (
787+ self , _text ("btn_stash" ), _text ("info_no_stash" ))
761788 return
762789 chosen , confirmed = QInputDialog .getItem (
763- self , "Pop Stash" , "Take back:" , stashes , 0 , False )
790+ self , _text ("dialog_stash_pop_title" ), _text ("dialog_stash_pop_prompt" ),
791+ stashes , 0 , False )
764792 if not confirmed or not chosen :
765793 return
766794 try :
767795 service .stash_pop (stashes .index (chosen ))
768796 except GitCommandError as error :
769- QMessageBox .critical (self , "Error" , f"Could not pop the stash :\n { error } " )
797+ QMessageBox .critical (self , "Error" , f"{ _text ( 'err_stash_pop' ) } :\n { error } " )
770798 return
771799 self ._refresh_change_list ()
772800
@@ -784,19 +812,23 @@ def on_resolve_conflict(self) -> None:
784812 return
785813 conflicts = service .conflicted_files ()
786814 if not conflicts :
787- QMessageBox .information (self , "Conflicts" , "Nothing is in conflict." )
815+ QMessageBox .information (
816+ self , _text ("dialog_resolve_title" ), _text ("info_no_conflicts" ))
788817 return
789818 chosen , confirmed = QInputDialog .getItem (
790- self , "Resolve Conflict" , "File:" , conflicts , 0 , False )
819+ self , _text ("dialog_resolve_title" ), _text ("dialog_resolve_file_prompt" ),
820+ conflicts , 0 , False )
791821 if not confirmed or not chosen :
792822 return
793823 keep , confirmed = QInputDialog .getItem (
794- self , "Resolve Conflict" , f"Keep which side of { chosen } ?" ,
824+ self , _text ("dialog_resolve_title" ),
825+ _text ("dialog_resolve_side_prompt" ).format (file = chosen ),
795826 ["ours" , "theirs" ], 0 , False )
796827 if not confirmed or not keep :
797828 return
798829 if not service .resolve_conflict (chosen , keep ):
799- QMessageBox .critical (self , "Error" , f"Could not resolve { chosen } ." )
830+ QMessageBox .critical (
831+ self , "Error" , _text ("err_resolve" ).format (file = chosen ))
800832 return
801833 self ._refresh_change_list ()
802834
0 commit comments