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

LocalizedStringConvertible #10

Merged
merged 2 commits into from
Mar 2, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
SwiftActions:
strategy:
matrix:
os: [macos-12, ubuntu-latest]
os: [macos-14, ubuntu-latest]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout Source
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Swift Build
uses: SwiftActions/SwiftBuild@main
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import LocaleSupport

### LocaleSupport

This module is focused on implementing localized strings within apps themselves. Highlighted by the `ExpressibleByLocalizedString` protocol.
This module is focused on implementing localized strings within apps themselves. Highlighted by the `LocalizedStringConvertible` protocol.

**Apple Platforms Note**:

Expand Down
2 changes: 1 addition & 1 deletion Sources/LocaleSupport/LocaleSupportConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ public struct LocaleSupportConfiguration {
private init() {
}

/// Characters that will be prepended/appended to any default `ExpressibleByLocalizedString` implementation.
/// Characters that will be prepended/appended to any default `LocalizedStringConvertible` implementation.
public static var defaultIndicators: (prefix: Character, suffix: Character)?
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import Foundation

/// Protocol to which an enumeration can conform to produce String localizations.
@available(*, deprecated, renamed: "LocalizedStringConvertible")
public typealias ExpressibleByLocalizedString = LocalizedStringConvertible

/// Protocol defining the properties needed to produce string localizations.
///
/// Localization is one of the key differentiators between *good* apps and *great* apps. Though many development teams
/// take on this challenge only after the application is 'complete'.
///
/// The aim of `ExpressibleByLocalizedString` is to quicken the process of localization, at the same time, taking much
/// The aim of `LocalizedStringConvertible` is to quicken the process of localization, at the same time, taking much
/// of the *guess-work* out of the picture.
///
/// When implemented on an `String` based enum, localization becomes a quick process that can be integrated at the
/// beginning of any project. An example implementation looks like this:
///
/// ```
/// /// Localized Strings for the MyAwesomeController class.
/// enum Strings: String, ExpressibleByLocalizedString {
/// enum Strings: String, LocalizedStringConvertible {
/// /// My Awesome Controller
/// case navigationTitle = "My Awesome Controller"
/// /// Next
Expand All @@ -29,7 +32,7 @@ import Foundation
///
/// For detailed information on using `String` resources, see
/// [Apple's Documentation](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html#//apple_ref/doc/uid/20000005-97055)
public protocol ExpressibleByLocalizedString {
public protocol LocalizedStringConvertible {
/// The '.strings' unique identifier for the localization
var key: String { get }

Expand Down Expand Up @@ -71,8 +74,8 @@ public protocol ExpressibleByLocalizedString {
var defaultIndicators: (prefix: Character, suffix: Character)? { get }
}

public extension ExpressibleByLocalizedString {
/// The value returned from 'NSLocalizedString(...)'
public extension LocalizedStringConvertible {
/// The value returned from 'NSLocalizedString(...)' or `Bundle.localizedString()`.
var localizedValue: String {
#if canImport(ObjectiveC)
return NSLocalizedString(key, tableName: tableName, bundle: bundle, value: defaultValue, comment: comment ?? "")
Expand All @@ -83,7 +86,7 @@ public extension ExpressibleByLocalizedString {
}

// MARK: - Key Generation
public extension ExpressibleByLocalizedString {
public extension LocalizedStringConvertible {
/// Generates a '.strings' key applying casing & prefixing as needed.
///
/// Each localization needs a unique 'key' to be defined in the '.strings' files. If a `prefix` is specific, it will
Expand Down Expand Up @@ -112,7 +115,7 @@ public extension ExpressibleByLocalizedString {
}

// MARK: - Default Parameters
public extension ExpressibleByLocalizedString {
public extension LocalizedStringConvertible {
var key: String { autogeneratedKey }
var bundle: Bundle { .main }
var tableName: String? { nil }
Expand All @@ -122,7 +125,7 @@ public extension ExpressibleByLocalizedString {
}

// MARK: - RawRepresentable Values
public extension ExpressibleByLocalizedString where Self: RawRepresentable, Self.RawValue == String {
public extension LocalizedStringConvertible where Self: RawRepresentable, Self.RawValue == String {
/// `rawValue` of a `String` RawRepresentable case (with indicators if present).
///
/// When an enumeration is declared to be using a `RawValue` of type `String`, the assumption will be that the value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ final class ExpressibleByLocalizedStringTests: XCTestCase {

private static var bundle: Bundle = .main

private enum Strings: String, ExpressibleByLocalizedString {
private enum Strings: String, LocalizedStringConvertible {
case alertTitle = "Delete Document"
case alertMessage = "Are you sure you want to delete the document?"
case confirm = "Yes"
Expand Down