Skip to content

Commit

Permalink
refactor: out-of-the-box
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon committed Aug 31, 2023
1 parent 227cd34 commit 8522a68
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/window/Translate/components/LanguageArea/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ export default function LanguageArea() {
const { t } = useTranslation();
useEffect(() => {
store.get('translate_source_language').then((v) => {
setSourceLanguage(v);
if (v) {
setSourceLanguage(v);
} else {
setSourceLanguage('auto');
}
});
store.get('translate_target_language').then((v) => {
setTargetLanguage(v);
if (v) {
setTargetLanguage(v);
} else {
setTargetLanguage(zh_cn);
}
});
}, []);

Expand Down Expand Up @@ -62,15 +70,15 @@ export default function LanguageArea() {
setTargetLanguage(oldSourceLanguage);
} else {
if (detectLanguage !== '') {
const defaultLanguage = await store.get('translate_target_language');
const defaultLanguage = (await store.get('translate_target_language')) ?? 'zh_cn';
if (targetLanguage === defaultLanguage) {
setTargetLanguage(detectLanguage);
} else {
setTargetLanguage(defaultLanguage);
}
} else {
const secondLanguage = await store.get('translate_second_language');
const defaultLanguage = await store.get('translate_target_language');
const secondLanguage = (await store.get('translate_second_language')) ?? 'en';
const defaultLanguage = (await store.get('translate_target_language')) ?? 'zh_cn';
if (targetLanguage === secondLanguage) {
setTargetLanguage(defaultLanguage);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/window/Translate/components/SourceArea/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function SourceArea() {
// image translate
} else {
let newText = text;
const deleteNewline = await store.get('translate_delete_newline');
const deleteNewline = (await store.get('translate_delete_newline')) ?? false;
if (deleteNewline) {
newText = text.replace(/\s+/g, ' ');
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/window/Translate/components/TargetArea/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function TargetArea(props) {
if (sourceLanguage in LanguageEnum && targetLanguage in LanguageEnum) {
let newTargetLanguage = targetLanguage;
if (sourceLanguage === 'auto' && targetLanguage === detectLanguage) {
newTargetLanguage = await store.get('translate_second_language');
newTargetLanguage = (await store.get('translate_second_language')) ?? 'en';
}
setIsLoading(true);
buildinServices[name]
Expand Down

0 comments on commit 8522a68

Please sign in to comment.