Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update openai-translator extension #15123

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions extensions/openai-translator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# OpenAI Translator Changelog

## [Added Recent Translate Language] - {PR_MERGE_DATE}

- Added the recent translation languages to the language dropdown list.

## [Dynamic OpenAI & Ollama Model List] - 2024-09-28

- Added dynamic retrieval of OpenAI & Ollama model lists.
Expand Down Expand Up @@ -55,8 +59,6 @@
- Auto exchange target and source when translate English and Chinese
- Fixed incomplete display of translation



## [Improve & Feature] - 2023-04-06

- Add SOCKS5 proxy suppoort
Expand All @@ -65,5 +67,4 @@
- "Word" mode
- Sync prompts from original openai translator


## [Initial Version] - 2023-03-10
3 changes: 2 additions & 1 deletion extensions/openai-translator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"author": "douo",
"contributors": [
"JoyG",
"leeonfield"
"leeonfield",
"ridemountainpig"
],
"categories": [
"Applications",
Expand Down
1 change: 1 addition & 0 deletions extensions/openai-translator/src/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default function getBase(
<LangDropdown
type={query.langType}
selectedStandardLang={query.langType == "To" ? query.to : query.from}
history={history}
onLangChange={query.langType == "To" ? query.updateTo : query.updateFrom}
/>
}
Expand Down
29 changes: 26 additions & 3 deletions extensions/openai-translator/src/views/lang-dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { List } from "@raycast/api";
import { supportLanguages } from "../providers/lang";
import { HistoryHook } from "../hooks/useHistory";

export function LangDropdown(props: {
type: string;
selectedStandardLang: string;
history: HistoryHook;
onLangChange: (newStandardLang: string) => void;
}) {
const { type, selectedStandardLang, onLangChange } = props;

const items = type == "To" ? supportLanguages : [["auto", "Auto"], ...supportLanguages];

const getRecentTranslations = () => {
const recentTranslationLangsSet = new Set(props.history.data?.map((item) => item.result.to));
return [...recentTranslationLangsSet].slice(0, 3);
};

const recentTranslationsLangs = getRecentTranslations();

return (
<List.Dropdown
tooltip="Select Target Language"
Expand All @@ -19,10 +28,24 @@ export function LangDropdown(props: {
onLangChange(newValue);
}}
>
{recentTranslationsLangs.length > 0 && (
<List.Dropdown.Section title="Recent Translate">
{recentTranslationsLangs.map((recentStandardLang) => {
const foundItem = items.find(([standardLang]) => standardLang === recentStandardLang);
if (!foundItem) return null;

const [, lang] = foundItem;
return <List.Dropdown.Item key={recentStandardLang} title={`${type} ${lang}`} value={recentStandardLang} />;
})}
</List.Dropdown.Section>
)}
<List.Dropdown.Section title={`Translate ${type}`}>
{items.map(([standardLang, lang]) => (
<List.Dropdown.Item key={standardLang} title={`${type} ${lang}`} value={standardLang} />
))}
{items.map(
([standardLang, lang]) =>
!recentTranslationsLangs.includes(standardLang) && (
<List.Dropdown.Item key={standardLang} title={`${type} ${lang}`} value={standardLang} />
),
)}
</List.Dropdown.Section>
</List.Dropdown>
);
Expand Down
Loading