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

Model Setup for String Catalog #14

Merged
merged 21 commits into from
Jan 5, 2024

Conversation

Uni-boy
Copy link
Contributor

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

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
Owner

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

@Uni-boy
Copy link
Contributor Author

Uni-boy commented Dec 19, 2023

Yeah my PR is ready.

Copy link
Owner

@superarts superarts left a comment

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.

StringCatalogEnum/Sources/StringCatalogEnum/model.swift Outdated Show resolved Hide resolved
StringCatalogEnum/Sources/StringCatalogEnum/model.swift Outdated Show resolved Hide resolved
}

struct StringInfo: Decodable {
Copy link
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
Copy link
Owner

@superarts superarts left a comment

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
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
Copy link
Contributor Author

Uni-boy commented Dec 31, 2023

I finalized the model and all tests passed.

@superarts
Copy link
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
Copy link
Contributor Author

Uni-boy commented Jan 3, 2024

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
@Uni-boy Uni-boy requested a review from superarts January 3, 2024 22:24
Copy link
Owner

@superarts superarts left a comment

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
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
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.

StringCatalogEnum/Sources/StringCatalogEnum/main.swift Outdated Show resolved Hide resolved
StringCatalogEnum/Sources/StringCatalogEnum/model.swift Outdated Show resolved Hide resolved
// let variations: Variations?
}

// struct Variations: Decodable {
Copy link
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
Copy link
Owner

@superarts superarts left a comment

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.

@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
Copy link
Owner

@superarts superarts left a comment

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
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
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
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