Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Strings: rename some vars for clarity purposes #33

Merged
merged 5 commits into from
May 8, 2017
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ _None_

* More variables have been deprecated, while new variables have been added.
[David Jennes](/~https://github.com/djbe)
[#5](/~https://github.com/SwiftGen/SwiftGenKit/issues/5)
[#13](/~https://github.com/SwiftGen/SwiftGenKit/issues/13)
[#27](/~https://github.com/SwiftGen/SwiftGenKit/issues/27)
[#33](/~https://github.com/SwiftGen/SwiftGenKit/issues/33)
* The `strings`, `structuredStrings` and `tableName` have been replaced by `tables`, which is an array of string tables, each with a `name` and a `strings` property.
* For each string, the `params` variable and it's subvariables (such as `names`, `count`, ...) have been replaced by `types`, which is an array of types.
* `enumName`, `sceneEnumName` and `segueEnumName` have been replaced by `param.enumName`, `param.sceneEnumName` and `param.segueEnumName` respectively. Templates should provide a default value for these in case the variables are empty.
Expand Down
16 changes: 8 additions & 8 deletions Documentation/Strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ will be parsed into the following structure (not showing the rest of the structu
The output context has the following structure:

- `tables`: `Array` — List of string tables
- `name` : `String` — name of the `.strings` file (usually `"Localizable"`)
- `strings`: `Array` — Tree structure of strings (based on dot syntax), each level has:
- `name` : `String` — name of the level (that is, part of the key split by `.` that we're describing)
- `strings`: `Array` — list of strings at this level:
- `key`: `String` — the full translation key, as it appears in the strings file
- `name` : `String` — name of the `.strings` file (usually `"Localizable"`)
- `levels`: `Array` — Tree structure of strings (based on dot syntax), each level has:
- `name` : `String` — name of the level (that is, part of the key split by `.` that we're describing)
- `children`: `Array` — list of sub-levels, repeating the same structure as a level
- `strings` : `Array` — list of strings at this level:
- `name` : `String` — contains only the last part of the key (after the last `.`)
(useful to do recursion when splitting keys against `.` for structured templates)
- `key` : `String` — the full translation key, as it appears in the strings file
- `translation`: `String` — the translation for that key in the strings file
- `types`: `Array<String>` — defined only if localized string has parameter placeholders like `%d` and `%@` etc.
Contains a list of types like `"String"`, `"Int"`, etc
- `keytail`: `String` — contains only the last part of the key (after the last `.`)
(useful to do recursion when splitting keys against `.` for structured templates)
- `subenums`: `Array` — list of sub-levels, repeating the structure mentioned above
36 changes: 21 additions & 15 deletions Sources/Stencil/StringsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,33 @@ private extension String {

/*
- `tables`: `Array` — List of string tables
- `name` : `String` — name of the `.strings` file (usually `"Localizable"`)
- `strings`: `Array` — Tree structure of strings (based on dot syntax), each level has:
- `name` : `String` — name of the level (that is, part of the key split by `.` that we're describing)
- `strings`: `Array` — list of strings at this level:
- `key`: `String` — the full translation key, as it appears in the strings file
- `name` : `String` — name of the `.strings` file (usually `"Localizable"`)
- `levels`: `Array` — Tree structure of strings (based on dot syntax), each level has:
- `name` : `String` — name of the level (that is, part of the key split by `.` that we're describing)
- `children`: `Array` — list of sub-levels, repeating the same structure as a level
- `strings` : `Array` — list of strings at this level:
- `name` : `String` — contains only the last part of the key (after the last `.`)
(useful to do recursion when splitting keys against `.` for structured templates)
- `key` : `String` — the full translation key, as it appears in the strings file
- `translation`: `String` — the translation for that key in the strings file
- `types`: `Array<String>` — defined only if localized string has parameter placeholders like `%d` and `%@` etc.
Contains a list of types like `"String"`, `"Int"`, etc
- `keytail`: `String` — contains only the last part of the key (after the last `.`)
(useful to do recursion when splitting keys against `.` for structured templates)
- `subenums`: `Array` — list of sub-levels, repeating the structure mentioned above
*/
extension StringsFileParser {
public func stencilContext(enumName: String = "L10n", tableName: String = "Localizable") -> [String: Any] {

let entryToStringMapper = { (entry: Entry, keyPath: [String]) -> [String: Any] in
var keyStructure = entry.keyStructure
Array(0..<keyPath.count).forEach { _ in keyStructure.removeFirst() }
let keytail = keyStructure.joined(separator: ".")
let levelName = keyStructure.joined(separator: ".")

var result: [String: Any] = [
"name": levelName,
"key": entry.key.newlineEscaped,
"translation": entry.translation.newlineEscaped,
"keytail": keytail

// NOTE: keytail is deprecated
"keytail": levelName
]

if entry.types.count > 0 {
Expand Down Expand Up @@ -67,7 +70,7 @@ extension StringsFileParser {
)
let tables: [[String: Any]] = [[
"name": tableName,
"strings": structuredStrings
"levels": structuredStrings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we keep the strings entry too (duplicate of levels) for 4.2.1 until we can remove it in 5.0.0, at least f we want to merge that for 4.2.1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lemme check, but I don't think tables.strings was ever released.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point, maybe not ^^

Copy link
Member Author

@djbe djbe May 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jup, never released:

(that's SwiftGenKit 1.0.1)

]]

return [
Expand Down Expand Up @@ -108,7 +111,7 @@ extension StringsFileParser {
structuredStrings["name"] = lastKeyPathComponent
}

var subenums: [[String: Any]] = []
var children: [[String: Any]] = []
let nextLevelKeyPaths: [[String]] = entries
.filter({ $0.keyStructure.count > keyPath.count+1 })
.map({ Array($0.keyStructure.prefix(keyPath.count+1)) })
Expand All @@ -127,15 +130,18 @@ extension StringsFileParser {
let entriesInKeyPath = entries.filter {
Array($0.keyStructure.map(normalize).prefix(nextLevelKeyPath.count)) == nextLevelKeyPath.map(normalize)
}
subenums.append(
children.append(
structure(entries: entriesInKeyPath,
atKeyPath: nextLevelKeyPath,
usingMapper: mapper)
)
}

if !subenums.isEmpty {
structuredStrings["subenums"] = subenums
if !children.isEmpty {
structuredStrings["children"] = children

// NOTE: These are deprecated variables
structuredStrings["subenums"] = children
}

return structuredStrings
Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources
Submodule Resources updated 44 files
+4 −0 CHANGELOG.md
+42 −42 Contexts/Fonts/customname.plist
+42 −42 Contexts/Fonts/defaults.plist
+222,328 −372 Contexts/Strings/customname.plist
+222,328 −372 Contexts/Strings/defaults.plist
+2 −2 Contexts/Strings/empty.plist
+30 −18 Contexts/Strings/entries.plist
+36 −3 Contexts/Strings/multiline.plist
+1,369 −105 Contexts/Strings/structuredonly.plist
+1,394 −162 Contexts/Strings/utf8.plist
+6 −6 Podfile.lock
+3 −3 Pods/Local Podspecs/StencilSwiftKit.podspec.json
+6 −6 Pods/Manifest.lock
+195 −187 Pods/Pods.xcodeproj/project.pbxproj
+1 −1 Pods/Stencil/README.md
+1 −1 Pods/Stencil/Sources/Context.swift
+75 −11 Pods/Stencil/Sources/ForTag.swift
+57 −23 Pods/Stencil/Sources/IfTag.swift
+2 −2 Pods/Stencil/Sources/Loader.swift
+7 −3 Pods/Stencil/Sources/Tokenizer.swift
+19 −20 Pods/StencilSwiftKit/README.md
+0 −0 Pods/StencilSwiftKit/Sources/CallMacroNodes.swift
+8 −7 Pods/StencilSwiftKit/Sources/Context.swift
+10 −9 Pods/StencilSwiftKit/Sources/Environment.swift
+33 −0 Pods/StencilSwiftKit/Sources/Filters+Numbers.swift
+169 −0 Pods/StencilSwiftKit/Sources/Filters+Strings.swift
+35 −157 Pods/StencilSwiftKit/Sources/Filters.swift
+37 −9 Pods/StencilSwiftKit/Sources/Parameters.swift
+1 −1 Pods/Target Support Files/Stencil/Info.plist
+1 −1 Pods/Target Support Files/StencilSwiftKit/Info.plist
+7 −9 templates/storyboards-default.stencil
+7 −9 templates/storyboards-lowercase.stencil
+3 −5 templates/storyboards-osx-default.stencil
+3 −5 templates/storyboards-osx-lowercase.stencil
+3 −5 templates/storyboards-osx-swift3.stencil
+7 −9 templates/storyboards-swift3.stencil
+7 −9 templates/storyboards-uppercase.stencil
+7 −7 templates/strings-default.stencil
+7 −7 templates/strings-dot-syntax-swift3.stencil
+7 −7 templates/strings-dot-syntax.stencil
+6 −6 templates/strings-genstrings.stencil
+7 −7 templates/strings-no-comments-swift3.stencil
+14 −14 templates/strings-structured.stencil
+7 −7 templates/strings-swift3.stencil