Skip to content

Model Setup for String Catalog - #14

Merged
superarts merged 21 commits into
superarts:masterfrom
Uni-boy:feature/create-decodable-models
Jan 5, 2024
Merged

superarts merged 21 commits into
superarts:masterfrom
Uni-boy:feature/create-decodable-models

Conversation

@Uni-boy

@Uni-boy Uni-boy commented Dec 19, 2023 •

Copy link
Copy Markdown
Contributor

Pull Request: XCString Model Setup, Add Tests, Other Fixes

Description

This pull request introduces the XCString model to our codebase.

The primary goal is to enhance our application's localization capabilities, making it easier to manage and use localized strings.

Related Issue

#1

Changes Made

  • Model Creation: Implemented the XCString model, designed to encapsulate localization logic and provide a more structured approach to handling localized strings.
  • Decoding Logic: Added functionality to decode localization data from JSON, enabling dynamic localization based on user preferences or system settings.
  • Unit Tests: Included comprehensive unit tests to validate the functionality of the XCString model, particularly focusing on its ability to correctly handle various localization scenarios.

Checklist

  • I have added appropriate comments/documentation.
  • All existing tests pass, and I have added new tests.
  • The commit messages are clear and follow best practices.

Additional Comments

I implemented the model according to the Json data listed in issue, but the actual json is more complex, so I commented out the model made for those extra attributes.

@superarts

Copy link
Copy Markdown
Owner

@Uni-boy is your PR ready for review please?

@Uni-boy

Uni-boy commented Dec 19, 2023

Copy link
Copy Markdown
Contributor Author

Yeah my PR is ready.

@superarts superarts left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why would we just add some passive data models without using them?

I recommend taking a look at closed PRs. See what kind of PRs are merged and what kind of PRs are rejected.

Comment thread StringCatalogEnum/Sources/StringCatalogEnum/model.swift Outdated
Comment thread StringCatalogEnum/Sources/StringCatalogEnum/model.swift Outdated
let strings: [String: StringInfo]
}

struct StringInfo: Decodable {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is it the best practice to put all structs in the same source file?

@Uni-boy
Uni-boy requested a review from superarts December 19, 2023 17:05

@superarts superarts left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Again, these structs should be consumed. Please check my previous comments: #14 (review)

@superarts

Copy link
Copy Markdown
Owner

@Uni-boy if you don't have any plan to update this PR, please feel free to close it. Thank you.

@Uni-boy
Uni-boy requested a review from superarts December 31, 2023 05:13
@Uni-boy

Uni-boy commented Dec 31, 2023

Copy link
Copy Markdown
Contributor Author

I finalized the model and all tests passed.

@superarts

Copy link
Copy Markdown
Owner

I finalized the model and all tests passed.

Please merge from master and resolve conflicts.

More importantly, when I said "these structs should be consumed", I meant the structs you created should replace codes like let strings = json["strings"] as? [String: Any] in main.swift. What do you think the codebase can benefit from some data models that are not used anywhere?

@Uni-boy

Uni-boy commented Jan 3, 2024

Copy link
Copy Markdown
Contributor Author

I finalized the model and all tests passed.

Please merge from master and resolve conflicts.

More importantly, when I said "these structs should be consumed", I meant the structs you created should replace codes like let strings = json["strings"] as? [String: Any] in main.swift. What do you think the codebase can benefit from some data models that are not used anywhere?

I applied the model to main.swift and solved the TODO in StringEnumHelper.swift

@Uni-boy Uni-boy changed the title set XCStrings model Model Setup for String Catalog Jan 3, 2024
Comment thread StringCatalogEnum/Sources/StringCatalogEnum/main.swift
@Uni-boy
Uni-boy requested a review from superarts January 3, 2024 22:24

@superarts superarts left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please address the obvious issues I pointed out, but my PR review is not finished yet. I'll add another review soon.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Revert this?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Delete xcode related files from git. You shouldn't use xcode for this project, but if you insist doing so (not recommended, I can see a sample xcode project being added in future, but not for the CLI tool itself), you can add this file to .gitignore.

Comment thread StringCatalogEnum/Sources/StringCatalogEnum/main.swift Outdated
Comment thread StringCatalogEnum/Sources/StringCatalogEnum/model.swift Outdated
Comment thread StringCatalogEnum/Sources/StringCatalogEnum/model.swift
// let variations: Variations?
}

// struct Variations: Decodable {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

These are dead codes too but I'll need to further look into it.

@Uni-boy
Uni-boy requested a review from superarts January 4, 2024 21:41

@superarts superarts left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Almost there! Just a few minor suggestions.

Comment thread StringCatalogEnum/Sources/StringCatalogEnumLibrary/StringEnumHelper.swift Outdated
Comment thread StringCatalogEnum/Sources/StringCatalogEnumLibrary/StringEnumHelper.swift Outdated
Comment thread StringCatalogEnum/Sources/StringCatalogEnumLibrary/StringEnumHelper.swift Outdated
@superarts superarts added the good first issue Good for newcomers label Jan 5, 2024
@Uni-boy
Uni-boy requested a review from superarts January 5, 2024 04:45

@superarts superarts left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please address this: #14 (comment)

And added some other suggestions regarding unit tests. Sorry I forgot them in my previous review.

let decoder = JSONDecoder()
expect{
try decoder.decode(Localizations.self, from: jsonData)
}.toNot(throwError())

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

One more thing: could you add some to(equal()) evaluation please?

},
"version" : "1.0"
}
"""

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

And here.

@Uni-boy
Uni-boy requested a review from superarts January 5, 2024 05:11

// Verify the contents of 'strings' dictionary
expect(decodedData.strings["Login"]).toNot(beNil())
expect(decodedData.strings["Login"]?.localizations?["en"]?.stringUnit?.state).to(equal("translated"))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Eventually we want to use Decodable for all these JSON objects, but this PR is good as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants