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

Support providing localized string for country and currency code #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

abuobaida
Copy link

No description provided.

@nekrich
Copy link
Contributor

nekrich commented Apr 13, 2017

@abuobaida I think those funcs should be in Localize class, not String.

extension Localize {
	
	/// Returns current locale.
	///
	/// - Returns: current locale.
	final class func currentLocale() -> Locale {
		return Locale(identifier: Localize.currentLanguage())
	}
	
	/// Returns a localized string for a specified ISO 4217 currency code.
	///
	/// - Parameter currencyCode: ISO 4217 currency code the currency whose name you want.
	/// - Returns: Localized string for a specified ISO 4217 currency code.
	final class func localizedCurrency(_ currencyCode: String) -> String {
		return currentLocale()
			.localizedString(forCurrencyCode: currencyCode) ?? currencyCode
	}
	
	/// Returns the localized string for the specified country code.
	///
	/// - Parameter countryCode: The country code indicating the country whose name you want.
	/// - Returns: Localized string for the specified country code.
	final class func localizedCountry(_ countryCode: String) -> String {
		return (currentLocale() as NSLocale)
			.localizedString(forCountryCode: countryCode) ?? countryCode
	}
	
}

@abuobaida
Copy link
Author

Thanks @nekrich, branch updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants