diff --git a/.swiftformat b/.swiftformat index 8cd6b86595..7401c87e55 100644 --- a/.swiftformat +++ b/.swiftformat @@ -1,6 +1,8 @@ --swiftversion 5.6 ---exclude ElementX/Sources/Generated,vendor,**/Package.swift,ElementX/Sources/Mocks/Generated +# Tchap: add TchapX generated files to exclusion list. +# --exclude ElementX/Sources/Generated,vendor,**/Package.swift,ElementX/Sources/Mocks/Generated +--exclude ElementX/Sources/Generated,vendor,**/Package.swift,ElementX/Sources/Mocks/Generated,TchapX/Sources/main/Generated --disable wrapMultiLineStatementBraces --disable hoistPatternLet diff --git a/.swiftlint.yml b/.swiftlint.yml index d8c789ffa0..86bc5eeab8 100755 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -18,6 +18,8 @@ included: excluded: - IntegrationTests - ElementX/Sources/Generated +# Tchap: add TchapX generated files to exclusion list. + - TchapX/Sources/main/Generated line_length: warning: 250 diff --git a/TchapX/SupportingFiles/target-development.yml b/TchapX/SupportingFiles/target-development.yml index 400cbbb9d8..4988d09f7c 100644 --- a/TchapX/SupportingFiles/target-development.yml +++ b/TchapX/SupportingFiles/target-development.yml @@ -118,7 +118,7 @@ targets: BASE_BUNDLE_IDENTIFIER: fr.gouv.tchapx.dev APP_NAME: TchapX-Development APP_DISPLAY_NAME: TchapX Development # The name used in the application. - + PRODUCT_NAME: $(APP_NAME) PRODUCT_BUNDLE_IDENTIFIER: $(BASE_BUNDLE_IDENTIFIER) ASSETCATALOG_COMPILER_APPICON_NAME: TchapX-icon @@ -129,7 +129,6 @@ targets: OTHER_SWIFT_FLAGS: - "-DIS_MAIN_APP -DIS_TCHAP_DEVELOPMENT" - preBuildScripts: - name: 🛠 SwiftGen runOnlyWhenInstalling: false @@ -138,7 +137,7 @@ targets: script: | export PATH="$PATH:/opt/homebrew/bin" if which swiftgen >/dev/null; then - swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml + swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml --config Tools/SwiftGen/swiftgen-config-tchap.yml else echo "warning: SwiftGen not installed, download from https://github.com/SwiftGen/SwiftGen" fi @@ -216,6 +215,7 @@ targets: - path: ../main/Sources excludes: - Other/Extensions/XCUIElement.swift + - path: ../main/Resources - path: ../../ElementX/Resources - path: ../../ElementX/SupportingFiles/Settings.bundle - path: ../development/Resources diff --git a/TchapX/SupportingFiles/target-production.yml b/TchapX/SupportingFiles/target-production.yml index 9d446f9d52..02e84d4194 100644 --- a/TchapX/SupportingFiles/target-production.yml +++ b/TchapX/SupportingFiles/target-production.yml @@ -128,7 +128,7 @@ targets: PILLS_UT_TYPE_IDENTIFIER: $(BASE_BUNDLE_IDENTIFIER).pills OTHER_SWIFT_FLAGS: - "-DIS_MAIN_APP -DIS_TCHAP_PRODUCTION" - + preBuildScripts: - name: 🛠 SwiftGen runOnlyWhenInstalling: false @@ -137,7 +137,7 @@ targets: script: | export PATH="$PATH:/opt/homebrew/bin" if which swiftgen >/dev/null; then - swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml + swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml --config Tools/SwiftGen/swiftgen-config-tchap.yml else echo "warning: SwiftGen not installed, download from https://github.com/SwiftGen/SwiftGen" fi @@ -215,6 +215,7 @@ targets: - path: ../main/Sources excludes: - Other/Extensions/XCUIElement.swift + - path: ../main/Resources - path: ../../ElementX/Resources - path: ../../ElementX/SupportingFiles/Settings.bundle - path: ../production/Resources diff --git a/TchapX/SupportingFiles/target-staging.yml b/TchapX/SupportingFiles/target-staging.yml index df831b736d..07e0808871 100644 --- a/TchapX/SupportingFiles/target-staging.yml +++ b/TchapX/SupportingFiles/target-staging.yml @@ -128,7 +128,7 @@ targets: PILLS_UT_TYPE_IDENTIFIER: $(BASE_BUNDLE_IDENTIFIER).pills OTHER_SWIFT_FLAGS: - "-DIS_MAIN_APP -DIS_TCHAP_STAGING" - + preBuildScripts: - name: 🛠 SwiftGen runOnlyWhenInstalling: false @@ -137,7 +137,7 @@ targets: script: | export PATH="$PATH:/opt/homebrew/bin" if which swiftgen >/dev/null; then - swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml + swiftgen config run --config Tools/SwiftGen/swiftgen-config.yml --config Tools/SwiftGen/swiftgen-config-tchap.yml else echo "warning: SwiftGen not installed, download from https://github.com/SwiftGen/SwiftGen" fi @@ -215,6 +215,7 @@ targets: - path: ../main/Sources excludes: - Other/Extensions/XCUIElement.swift + - path: ../main/Resources - path: ../../ElementX/Resources - path: ../../ElementX/SupportingFiles/Settings.bundle - path: ../staging/Resources diff --git a/TchapX/development/SupportingFiles/NSE/target.yml b/TchapX/development/SupportingFiles/NSE/target.yml index ad1ae35bce..07184f6654 100644 --- a/TchapX/development/SupportingFiles/NSE/target.yml +++ b/TchapX/development/SupportingFiles/NSE/target.yml @@ -119,4 +119,5 @@ targets: - path: ../../../../ElementX/Sources/AppHooks/AppHooks.swift - path: ../../../../ElementX/Sources/AppHooks/Hooks/ClientBuilderHook.swift - path: ../PrivacyInfo.xcprivacy -# - path: ../../../main/Sources/Other/Helpers/TchapX-String.swift \ No newline at end of file + - path: ../../../main/Sources/Generated/TchapAssets.swift + - path: ../../../main/Sources/Generated/TchapStrings.swift \ No newline at end of file diff --git a/TchapX/main/Resources/Assets.xcassets/Contents.json b/TchapX/main/Resources/Assets.xcassets/Contents.json new file mode 100644 index 0000000000..73c00596a7 --- /dev/null +++ b/TchapX/main/Resources/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/TchapX/main/Resources/Localizations/en.lproj/TchapLocalizable.strings b/TchapX/main/Resources/Localizations/en.lproj/TchapLocalizable.strings new file mode 100644 index 0000000000..60aa89f927 --- /dev/null +++ b/TchapX/main/Resources/Localizations/en.lproj/TchapLocalizable.strings @@ -0,0 +1,8 @@ +/* + Localizable.strings + TchapX + + Created by Nicolas Buquet on 18/11/2024. + Copyright © 2024 Tchap. All rights reserved. +*/ + diff --git a/TchapX/main/Resources/Localizations/en.lproj/TchapUntranslated.strings b/TchapX/main/Resources/Localizations/en.lproj/TchapUntranslated.strings new file mode 100644 index 0000000000..ece45612b0 --- /dev/null +++ b/TchapX/main/Resources/Localizations/en.lproj/TchapUntranslated.strings @@ -0,0 +1,8 @@ +/* + Untranslated.strings + TchapX + + Created by Nicolas Buquet on 18/11/2024. + Copyright © 2024 Tchap. All rights reserved. +*/ + diff --git a/TchapX/main/Resources/Localizations/fr.lproj/TchapLocalizable.strings b/TchapX/main/Resources/Localizations/fr.lproj/TchapLocalizable.strings new file mode 100644 index 0000000000..60aa89f927 --- /dev/null +++ b/TchapX/main/Resources/Localizations/fr.lproj/TchapLocalizable.strings @@ -0,0 +1,8 @@ +/* + Localizable.strings + TchapX + + Created by Nicolas Buquet on 18/11/2024. + Copyright © 2024 Tchap. All rights reserved. +*/ + diff --git a/TchapX/main/Sources/Generated/TchapAssets.swift b/TchapX/main/Sources/Generated/TchapAssets.swift new file mode 100644 index 0000000000..016b5164a5 --- /dev/null +++ b/TchapX/main/Sources/Generated/TchapAssets.swift @@ -0,0 +1,38 @@ +// swiftlint:disable all +// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen + +#if os(macOS) + import AppKit +#elseif os(iOS) + import UIKit +#elseif os(tvOS) || os(watchOS) + import UIKit +#endif +#if canImport(SwiftUI) + import SwiftUI +#endif + +// Deprecated typealiases + +// swiftlint:disable superfluous_disable_command file_length implicit_return + +// MARK: - Asset Catalogs + +// swiftlint:disable identifier_name line_length nesting type_body_length type_name +internal enum TchapAssets { +} +// swiftlint:enable identifier_name line_length nesting type_body_length type_name + +// MARK: - Implementation Details + +// swiftlint:disable convenience_type +private final class BundleToken { + static let bundle: Bundle = { + #if SWIFT_PACKAGE + return Bundle.module + #else + return Bundle(for: BundleToken.self) + #endif + }() +} +// swiftlint:enable convenience_type diff --git a/TchapX/main/Sources/Generated/TchapStrings+Untranslated.swift b/TchapX/main/Sources/Generated/TchapStrings+Untranslated.swift new file mode 100644 index 0000000000..d4bb6ab5bb --- /dev/null +++ b/TchapX/main/Sources/Generated/TchapStrings+Untranslated.swift @@ -0,0 +1,28 @@ +// swiftlint:disable all +// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen + +import Foundation + +// swiftlint:disable superfluous_disable_command file_length implicit_return + +// MARK: - Strings + +// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length +// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces +internal enum TchapUntranslatedL10n { +} +// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length +// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces + +// MARK: - Implementation Details + +extension TchapUntranslatedL10n { + static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String { + // No need to check languages, we always default to en for untranslated strings + guard let bundle = Bundle.lprojBundle(for: "en") else { return key } + let format = NSLocalizedString(key, tableName: table, bundle: bundle, comment: "") + return String(format: format, locale: Locale(identifier: "en"), arguments: args) + } +} + +// swiftlint:enable all diff --git a/TchapX/main/Sources/Generated/TchapStrings.swift b/TchapX/main/Sources/Generated/TchapStrings.swift new file mode 100644 index 0000000000..e7acda9157 --- /dev/null +++ b/TchapX/main/Sources/Generated/TchapStrings.swift @@ -0,0 +1,41 @@ +// swiftlint:disable all +// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen + +import Foundation + +// swiftlint:disable superfluous_disable_command file_length implicit_return + +// MARK: - Strings + +// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length +// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces +internal enum TchapL10n { +} +// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length +// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces + +// MARK: - Implementation Details + +extension TchapL10n { + static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String { + // Use preferredLocalizations to get a language that is in the bundle and the user's preferred list of languages. + let languages = Bundle.overrideLocalizations ?? Bundle.app.preferredLocalizations + + for language in languages { + if let translation = trIn(language, table, key, args) { + return translation + } + } + return Bundle.app.developmentLocalization.flatMap { trIn($0, table, key, args) } ?? key + } + + private static func trIn(_ language: String, _ table: String, _ key: String, _ args: CVarArg...) -> String? { + guard let bundle = Bundle.lprojBundle(for: language) else { return nil } + let format = NSLocalizedString(key, tableName: table, bundle: bundle, comment: "") + let translation = String(format: format, locale: Locale(identifier: language), arguments: args) + guard translation != key else { return nil } + return translation + } +} + +// swiftlint:enable all diff --git a/TchapX/production/SupportingFiles/NSE/target.yml b/TchapX/production/SupportingFiles/NSE/target.yml index 9c6ef5a107..a70a54accc 100644 --- a/TchapX/production/SupportingFiles/NSE/target.yml +++ b/TchapX/production/SupportingFiles/NSE/target.yml @@ -119,4 +119,5 @@ targets: - path: ../../../../ElementX/Sources/AppHooks/AppHooks.swift - path: ../../../../ElementX/Sources/AppHooks/Hooks/ClientBuilderHook.swift - path: ../PrivacyInfo.xcprivacy -# - path: ../../../main/Sources/Other/Helpers/TchapX-String.swift \ No newline at end of file + - path: ../../../main/Sources/Generated/TchapAssets.swift + - path: ../../../main/Sources/Generated/TchapStrings.swift \ No newline at end of file diff --git a/TchapX/staging/SupportingFiles/NSE/target.yml b/TchapX/staging/SupportingFiles/NSE/target.yml index 55ce91cf58..ae1c484ff0 100644 --- a/TchapX/staging/SupportingFiles/NSE/target.yml +++ b/TchapX/staging/SupportingFiles/NSE/target.yml @@ -119,4 +119,5 @@ targets: - path: ../../../../ElementX/Sources/AppHooks/AppHooks.swift - path: ../../../../ElementX/Sources/AppHooks/Hooks/ClientBuilderHook.swift - path: ../PrivacyInfo.xcprivacy -# - path: ../../../main/Sources/Other/Helpers/TchapX-String.swift \ No newline at end of file + - path: ../../../main/Sources/Generated/TchapAssets.swift + - path: ../../../main/Sources/Generated/TchapStrings.swift \ No newline at end of file diff --git a/Tools/SwiftGen/swiftgen-config-tchap.yml b/Tools/SwiftGen/swiftgen-config-tchap.yml new file mode 100755 index 0000000000..759c12750d --- /dev/null +++ b/Tools/SwiftGen/swiftgen-config-tchap.yml @@ -0,0 +1,29 @@ +input_dir: ../../TchapX/main/ +output_dir: ../../TchapX/main/Sources/Generated/ +xcassets: + inputs: + - Resources/Assets.xcassets + outputs: + templateName: swift5 + output: TchapAssets.swift + params: + enumName: TchapAssets # To not conflict with ElementX/Assets.swift +strings: + - inputs: Resources/Localizations/en.lproj + filter: TchapLocalizable* + outputs: + templatePath: Templates/Strings/structured-swift5-element.stencil + output: TchapStrings.swift + params: + enumName: TchapL10n + lookupFunction: tr # used for the loc to be computed variables + publicAccess: false + - inputs: Resources/Localizations/en.lproj + filter: TchapUntranslated* + outputs: + templatePath: Templates/Strings/structured-swift5-element-untranslated.stencil + output: TchapStrings+Untranslated.swift + params: + enumName: TchapUntranslatedL10n + lookupFunction: tr # used for the loc to be computed variables + publicAccess: false diff --git a/codecov.yml b/codecov.yml index a13d2ab90a..7708784abd 100644 --- a/codecov.yml +++ b/codecov.yml @@ -19,6 +19,8 @@ ignore: - "**/Mock*.swift" - "**/*Mock.swift" - "**/*Proxy.swift" +# Tchap: add TchapX generated files to exclusion list. + - "TchapX/Sources/main/Generated" flag_management: default_rules: