Skip to content

Identify BCP 47 identifiers and turn them into Locale objects #1

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

Open
zadr opened this issue Jan 2, 2017 · 2 comments
Open

Identify BCP 47 identifiers and turn them into Locale objects #1

zadr opened this issue Jan 2, 2017 · 2 comments

Comments

@zadr
Copy link
Owner

zadr commented Jan 2, 2017

BCP 47 defines Tags for Identifying Languages.

Given the following JSON:

{
    "language": "en",
    "foo": true
}

j2s will currently output the following Swift code:

public struct Root {
	let foo: Bool
	let language: String

	init?(_ dictionary: [String: Any]) {
		if let foo = dictionary["foo"] as? Bool {
			self.foo = foo
		} else {
			return nil
		}
		
		if let language = dictionary["language"] as? String {
			self.language = language
		} else {
			return nil
		}
	}
}

but it might be useful if could identify BCP 47 identifiers and instead output code using Locales, such as:

public struct Root {
	let foo: Bool
	let language: String

	init?(_ dictionary: [String: Any]) {
		if let foo = dictionary["foo"] as? Bool {
			self.foo = foo
		} else {
			return nil
		}
		
		if let language = dictionary["language"] as? String {
			Locale(localeIdentifier: language)
		} else {
			return nil
		}
	}
}
@zadr
Copy link
Owner Author

zadr commented Jan 4, 2017

fixed by f0d5fa5

@zadr zadr closed this as completed Jan 4, 2017
@zadr
Copy link
Owner Author

zadr commented Jun 27, 2017

this was un-fixed after starting to generate Codable-compliant code

@zadr zadr reopened this Jun 27, 2017
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

No branches or pull requests

1 participant