-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change localization interpolation (#161)
* Change the string interpolation for the localization * Avoid type casting by using a type erasure * Return the fallback literal instead of throwing an error * Try to solve the test errors * Replace the argument placeholders with the format specifiers used in swift
- Loading branch information
1 parent
18061c6
commit 275404a
Showing
19 changed files
with
335 additions
and
164 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
45 changes: 45 additions & 0 deletions
45
Sources/HTMLKit/Framework/Localization/InterpolationArgument.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,45 @@ | ||
import Foundation | ||
|
||
/// An enum that represents the data types of arguments used in interpolation. | ||
/// | ||
/// Each case corresponds to a specific data type and provides a placeholder | ||
/// that can be used for replacing values in the localized string. | ||
@_documentation(visibility: internal) | ||
public enum InterpolationArgument { | ||
|
||
/// Holds an integer value | ||
case int(Int) | ||
|
||
/// Holds a string value | ||
case string(String) | ||
|
||
/// Holds a double value | ||
case double(Double) | ||
|
||
/// Holds a float value | ||
case float(Float) | ||
|
||
/// Holds a date value | ||
case date(Date) | ||
|
||
/// The placeholder used for string interpolation | ||
internal var placeholder: String { | ||
|
||
switch self { | ||
case .int(_): | ||
return "%lld" | ||
|
||
case .string(_): | ||
return "%@" | ||
|
||
case .double(_): | ||
return "%f" | ||
|
||
case .float(_): | ||
return "%f" | ||
|
||
case .date(_): | ||
return "%@" | ||
} | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
Sources/HTMLKit/Framework/Localization/LocalizedString.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,23 @@ | ||
import Foundation | ||
|
||
/// A type thats holds the information for the localization | ||
@_documentation(visibility: internal) | ||
public struct LocalizedString: Content { | ||
|
||
/// The key of the translation value | ||
internal let key: LocalizedStringKey | ||
|
||
/// The name of the translation table | ||
internal let table: String? | ||
|
||
/// Initializes a localized string with context | ||
/// | ||
/// - Parameters: | ||
/// - key: The string key to be translated | ||
/// - table: The table where the string key should be looked up. Default is nil. | ||
public init(key: LocalizedStringKey, table: String? = nil) { | ||
|
||
self.key = key | ||
self.table = table | ||
} | ||
} |
Oops, something went wrong.