forked from element-hq/element-x-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Build] Gérer des assets et des strings propres à TchapX
- Loading branch information
Nicolas Buquet
committed
Nov 18, 2024
1 parent
b827738
commit 7f20232
Showing
17 changed files
with
188 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
TchapX/main/Resources/Localizations/en.lproj/TchapLocalizable.strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Localizable.strings | ||
TchapX | ||
|
||
Created by Nicolas Buquet on 18/11/2024. | ||
Copyright © 2024 Tchap. All rights reserved. | ||
*/ | ||
|
8 changes: 8 additions & 0 deletions
8
TchapX/main/Resources/Localizations/en.lproj/TchapUntranslated.strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Untranslated.strings | ||
TchapX | ||
|
||
Created by Nicolas Buquet on 18/11/2024. | ||
Copyright © 2024 Tchap. All rights reserved. | ||
*/ | ||
|
8 changes: 8 additions & 0 deletions
8
TchapX/main/Resources/Localizations/fr.lproj/TchapLocalizable.strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Localizable.strings | ||
TchapX | ||
|
||
Created by Nicolas Buquet on 18/11/2024. | ||
Copyright © 2024 Tchap. All rights reserved. | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
28 changes: 28 additions & 0 deletions
28
TchapX/main/Sources/Generated/TchapStrings+Untranslated.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters