Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Add new parameter for date formats, and default to en_US #287

Closed
wants to merge 3 commits into from

Conversation

f-meloni
Copy link

Hello everyone 馃憢馃徎

First of all, thank you for this great tool!

While I was generating some documentation I've noticed that it was using my locale, which makes the result odd, because uses an italian word in the middle of an english sentence.

Schermata 2021-05-22 alle 20 58 53

I've then added a new option (that defaults to en_US) to specify the locale for the dates that are printed by swift docs.
I could just hardcode en_US there, but I thought that making it explicit with an option and allow the user to modify it was a better choice.

Schermata 2021-05-22 alle 21 32 42

And now is correct also with my italian locale

Schermata 2021-05-22 alle 21 47 38

@@ -2,6 +2,7 @@ import SwiftSemantics
import SwiftDoc
import CommonMarkBuilder
import HypertextLiteral
import struct Foundation.Locale
Copy link
Author

Choose a reason for hiding this comment

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

In some files the compiler was having some issues with Protocol once Foundation was imported, also when I used SwiftSemantics.Protocol instead of just Protocol, so I've imported only Foundation.Locale where the issue was happening

@@ -72,11 +78,11 @@ extension SwiftDoc {
for symbol in module.interface.topLevelSymbols.filter(symbolFilter) {
switch symbol.api {
case is Class, is Enumeration, is Structure, is Protocol:
pages[route(for: symbol)] = TypePage(module: module, symbol: symbol, baseURL: baseURL, includingChildren: symbolFilter)
pages[route(for: symbol)] = TypePage(module: module, symbol: symbol, baseURL: baseURL, datesLocale: datesLocale, includingChildren: symbolFilter)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid long lines, as with these changes it now requires horizontal scrolling to review even on a wide screen, and makes it even harder on narrow screens. This is applicable to the rest of the long lines in this diff.

Suggested change
pages[route(for: symbol)] = TypePage(module: module, symbol: symbol, baseURL: baseURL, datesLocale: datesLocale, includingChildren: symbolFilter)
pages[route(for: symbol)] = TypePage(
module: module,
symbol: symbol,
baseURL: baseURL,
datesLocale: datesLocale,
includingChildren: symbolFilter
)

Copy link
Author

@f-meloni f-meloni May 23, 2021

Choose a reason for hiding this comment

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

Would be cool to some swiftformat and swiftlint config to automate the check and possibly also the formatting part :P
What do you think?
I can help to set it up if you want

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you, sounds good to me! @mattt WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we are going to add linting, I would suggest that we should stick to swift-format for linting rather than using swift-lint. As to setting that up, its pretty trivial (there is an example at https://github.com/compnerd/swift-win32/blob/main/.github/workflows/lint.yml).

f-meloni and others added 2 commits May 23, 2021 12:12
Co-authored-by: Max Desiatov <max@desiatov.com>
@@ -37,6 +40,8 @@ struct FooterPage: Page {
}

var html: HypertextLiteral.HTML {
dateFormatter.locale = datesLocale
Copy link
Author

Choose a reason for hiding this comment

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

I've also noticed that there is a discrepancy with the Markdown footer, that uses "Generated at \(timestamp) using [swift-doc](\(href)) \(SwiftDoc.configuration.version)." while it could use "Generated on \(dateString)" instead.
WDYT?

Copy link
Contributor

@mattt mattt left a comment

Choose a reason for hiding this comment

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

Thanks so much for taking the time to put this PR together, @f-meloni. I'd be interested to explore a full localization strategy for swift-doc (#290). For now, I think the best solution would be to configure date formatters to use an en_US locale (#289).

@mattt mattt closed this Jun 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants