Skip to content

Commit

Permalink
LocalizedStringConvertible (#10)
Browse files Browse the repository at this point in the history
* Renamed 'ExpressibleByLocalizedString' to 'LocalizedStringConvertible'

* Updated checkout and macos target
  • Loading branch information
richardpiazza authored Mar 2, 2024
1 parent fafb099 commit c2dc014
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
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

0 comments on commit c2dc014

Please sign in to comment.