Skip to content
Merged
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
129 changes: 129 additions & 0 deletions ScreenTranslate.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@
86DCC59B2F56BB9D000ECF4B /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = 86DCC59A2F56BB9D000ECF4B /* Sparkle */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
SC000032 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = SC000010 /* Project object */;
proxyType = 1;
remoteGlobalIDString = SC000006;
remoteInfo = ScreenTranslate;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
SC000001 /* ScreenTranslate.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ScreenTranslate.app; sourceTree = BUILT_PRODUCTS_DIR; };
SC000022 /* ScreenTranslateTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ScreenTranslateTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
Expand All @@ -33,6 +44,11 @@
path = ScreenTranslate;
sourceTree = "<group>";
};
SC000021 /* ScreenTranslateTests */ = {
isa = PBXFileSystemSynchronizedRootGroup;
path = ScreenTranslateTests;
sourceTree = "<group>";
};
/* End PBXFileSystemSynchronizedRootGroup section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -51,6 +67,7 @@
isa = PBXGroup;
children = (
SC000002 /* ScreenTranslate */,
SC000021 /* ScreenTranslateTests */,
SC000005 /* Products */,
);
sourceTree = "<group>";
Expand All @@ -59,6 +76,7 @@
isa = PBXGroup;
children = (
SC000001 /* ScreenTranslate.app */,
SC000022 /* ScreenTranslateTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -90,6 +108,29 @@
productReference = SC000001 /* ScreenTranslate.app */;
productType = "com.apple.product-type.application";
};
SC000023 /* ScreenTranslateTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = SC000026 /* Build configuration list for PBXNativeTarget "ScreenTranslateTests" */;
buildPhases = (
SC000024 /* Sources */,
SC000025 /* Frameworks */,
SC000027 /* Resources */,
);
buildRules = (
);
dependencies = (
SC000033 /* PBXTargetDependency */,
);
fileSystemSynchronizedGroups = (
SC000021 /* ScreenTranslateTests */,
);
name = ScreenTranslateTests;
packageProductDependencies = (
);
productName = ScreenTranslateTests;
productReference = SC000022 /* ScreenTranslateTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
Expand All @@ -103,6 +144,10 @@
SC000006 = {
CreatedOnToolsVersion = 26.2;
};
SC000023 = {
CreatedOnToolsVersion = 26.2;
TestTargetID = SC000006;
};
};
};
buildConfigurationList = SC000011 /* Build configuration list for PBXProject "ScreenTranslate" */;
Expand Down Expand Up @@ -132,6 +177,7 @@
projectRoot = "";
targets = (
SC000006 /* ScreenTranslate */,
SC000023 /* ScreenTranslateTests */,
);
};
/* End PBXProject section */
Expand All @@ -144,6 +190,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
SC000027 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
Expand All @@ -170,8 +223,33 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
SC000024 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXFrameworksBuildPhase section */
SC000025 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXTargetDependency section */
SC000033 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = SC000006 /* ScreenTranslate */;
targetProxy = SC000032 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin XCBuildConfiguration section */
SC000012 /* Debug */ = {
isa = XCBuildConfiguration;
Expand Down Expand Up @@ -367,6 +445,48 @@
};
name = Release;
};
SC000028 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 26.0;
PRODUCT_BUNDLE_IDENTIFIER = com.screentranslate.appTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 6.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ScreenTranslate.app/Contents/MacOS/ScreenTranslate";
TEST_TARGET_NAME = ScreenTranslate;
};
name = Debug;
};
SC000029 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 26.0;
PRODUCT_BUNDLE_IDENTIFIER = com.screentranslate.appTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 6.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ScreenTranslate.app/Contents/MacOS/ScreenTranslate";
TEST_TARGET_NAME = ScreenTranslate;
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
Expand All @@ -388,6 +508,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
SC000026 /* Build configuration list for PBXNativeTarget "ScreenTranslateTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
SC000028 /* Debug */,
SC000029 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ final class OnboardingViewModel {
translationTestSuccess = true
} else {
let config = TranslationEngine.Configuration(
sourceLanguage: nil,
targetLanguage: TranslationLanguage.chineseSimplified,
timeout: 10.0,
autoDetectSourceLanguage: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,11 @@ final class TextTranslationPopupController: NSObject {
}

private func languageDisplayName(for code: String?) -> String {
guard let code = code, !code.isEmpty else {
return NSLocalizedString("language.auto", value: "Auto Detected", comment: "")
}
if let languageName = Locale.current.localizedString(forLanguageCode: code) {
return languageName
}
return code.uppercased()
TranslationLanguage.displayName(
for: code,
locale: .current,
autoDisplayName: NSLocalizedString("language.auto", value: "Auto Detected", comment: "")
)
}

private func calculateWindowSize(originalText: String, translatedText: String) -> NSSize {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,15 @@ final class TranslationFlowController {

let settings = AppSettings.shared
let targetLanguage = settings.translationTargetLanguage?.rawValue ?? "zh-Hans"
let sourceLanguage = settings.translationSourceLanguage.rawValue
let sourceLanguage: String? = settings.translationSourceLanguage == .auto
? nil
: settings.translationSourceLanguage.rawValue
let engine = settings.translationEngine

let texts = analysisResult.segments.map { $0.text }
let filteredAnalysisResult = analysisResult.filteredForTranslation()
if filteredAnalysisResult.segments.isEmpty {
throw TranslationFlowError.noTextFound
}
let texts = filteredAnalysisResult.segments.map(\.text)

if #available(macOS 13.0, *) {
let translatedSegments = try await TranslationService.shared.translate(
Expand All @@ -207,7 +212,7 @@ final class TranslationFlowController {
)

// Merge bounding box info from VLM analysis back into translated segments
bilingualSegments = zip(analysisResult.segments, translatedSegments).map { original, translated in
bilingualSegments = zip(filteredAnalysisResult.segments, translatedSegments).map { original, translated in
BilingualSegment(
segment: original,
translatedText: translated.translated,
Expand Down
74 changes: 60 additions & 14 deletions ScreenTranslate/Models/AppLanguage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ enum AppLanguage: String, CaseIterable, Identifiable, Sendable {
case english = "en"
/// Simplified Chinese
case simplifiedChinese = "zh-Hans"
/// German
case german = "de"
/// Spanish
case spanish = "es"
/// French
case french = "fr"
/// Italian
case italian = "it"
/// Japanese
case japanese = "ja"
/// Korean
case korean = "ko"
/// Portuguese
case portuguese = "pt"
/// Russian
case russian = "ru"

var id: String { rawValue }

Expand All @@ -21,6 +37,22 @@ enum AppLanguage: String, CaseIterable, Identifiable, Sendable {
return "English"
case .simplifiedChinese:
return "简体中文"
case .german:
return "Deutsch"
case .spanish:
return "Español"
case .french:
return "Français"
case .italian:
return "Italiano"
case .japanese:
return "日本語"
case .korean:
return "한국어"
case .portuguese:
return "Português"
case .russian:
return "Русский"
}
}

Expand All @@ -29,17 +61,35 @@ enum AppLanguage: String, CaseIterable, Identifiable, Sendable {
switch self {
case .system:
return nil
case .english:
return "en"
case .simplifiedChinese:
return "zh-Hans"
default:
return rawValue
}
}

/// All supported language codes (excluding system)
static var supportedLanguageCodes: [String] {
allCases.compactMap { $0.localeIdentifier }
}

static func from(localeIdentifier: String) -> AppLanguage? {
let normalizedIdentifier = localeIdentifier.replacingOccurrences(of: "_", with: "-").lowercased()

if normalizedIdentifier.hasPrefix("zh-hans")
|| normalizedIdentifier == "zh-cn"
|| normalizedIdentifier == "zh-sg" {
return .simplifiedChinese
}

return allCases.first { language in
guard language != .system else {
return false
}

let languageCode = language.rawValue.lowercased()
return normalizedIdentifier == languageCode
|| normalizedIdentifier.hasPrefix(languageCode + "-")
}
}
}

/// Manages application language settings and provides runtime language switching.
Expand Down Expand Up @@ -100,19 +150,15 @@ final class LanguageManager {
}

// For system, detect the preferred language
let preferredLanguages = Locale.preferredLanguages
for preferred in preferredLanguages {
// Check if we support this language
if preferred.hasPrefix("zh-Hans") || preferred.hasPrefix("zh_Hans") || preferred == "zh-CN" {
return "zh-Hans"
}
if preferred.hasPrefix("en") {
return "en"
for preferredLanguage in Locale.preferredLanguages {
if let matchedLanguage = AppLanguage.from(localeIdentifier: preferredLanguage),
let localeIdentifier = matchedLanguage.localeIdentifier {
return localeIdentifier
}
}

// Default to English
return "en"
return AppLanguage.english.rawValue
}

// MARK: - Private Methods
Expand Down
Loading