-
Notifications
You must be signed in to change notification settings - Fork 102
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
Adding localization support to improve accessibility #76
Comments
Someone else asked me about this by email, and I think it's a great idea – I'd love for Ignite sites to be localized, where possible!
I don't fully see why JavaScript is needed. This should all be done at build time, no?
String catalogs would be a great choice, as long as they are fully supported outside of macOS; people have already started building Ignite sites on Linux.
Everything should be flattened at build time, so the whole thing remains static. That would mean using the base language by default (perhaps by changing languages to an array, then using whichever one is listed first?), then push the rest to /es/original/path, /fr/original/path, etc. This should mean no redirect is needed, and there would be no opting in or out. That might be overly simplistic, though, so I'd be keen to hear more on why you want to introduce javaScript here. In my head, the greatest challenge would be around making sure all a site's content is localized to the supported languages, or if we even want to push for that. For example, if I say my site is English first then French second, what happens if one of my Markdown posts is missing in French? Perhaps this is just a configuration option, but it could get rather messy with things like tag pages. |
When you say "started building on Linux" you mean they do the entire editing part there? So no Xcode available? If that's what you mean, then I understand that it might not be optimal to use String Catalogs as a format due to lack of a GUI editor. But I'm also not sure if any other localization file format has an editor there, and String Catalogs are quite readable JSON at the core, so it might still be a viable option. Building and extracting localizations from the String Catalog should be fully supported even with String Catalogs as we would do the parsing all in Swift code. So if general editing and hosting on Linux is your only concern, that shouldn't be a problem.
I agree in general with flattening everything at build time. But the reason I would still add some Javascript is for automatic browser language preference detection. So when a user who prefers French visits the site it automatically shows the French site, not the English one. This could not be achieved without some JavaScript AFAIK, but it would be just a couple lines of code, and we could make it opt-in and not render it at all if only one language is supported. It should also only be there for the default path without a locale inside, so when users call This could be important for many use cases where people share links to their app landing page, for example. While they could share different language links with different audiences, at least for the home page of a domain you don't usually do that, you just call the domain and expect it to be in the language you need, like how it works on App Store Connect. Of course, we could start without this feature. But as an opt-in one I don't see a problem and I would be up to implement it, as I need it for my app landing pages that I'm planning to build with Ignite.
Note sure what you mean with tag pages, but if we use String Catalogs and localization markers like |
|
Without automatic language selection, I can't use Ignite for any of my planned use cases as my apps are multi-language and my app landing pages should be as well. If that's a direction you don't want to go (which I totally respect, of course), I might have to create a fork and maintain that with the dynamic features I need, if that's okay with you. For the tag pages, aren't they generated like any other page? Why couldn't they be localized as well with links to all localized pages that have a certain tag? Even the tags themselves could be localized, internally they would keep the default locale name but when shown to viewers they could be localized like any other content. I don't see how String Catalogs are a problem there. |
It's an open-source project; you can fork it whenever you want. Automatic language selection will not happen. If you want to direct folks to a particular part of your site, that should be done in your app, in your App Store Connect settings, or similar – you know what language they actually want there, because it's the setting on their phone or overridden on a per-app basis in Settings, and correctly takes into account the user's actual preference rather than trying to auto-detect. If you want users of your app who have expressly said "Ignore my phone's setting, use English for this app" to visit your site and suddenly be given French because that's what Safari is set to, that's down to you. This is, as far as I know, fairly standard behavior for the web: if I enable French as the primary language on my iPhone then visit apple.com, I get the US English site. If I use US English on my iPad and visit apple.com/jp, I get the Japanese site. The same is true for microsoft.com, intel.com, amd.com, and many more. This appears to be common, so it's hardly unprecedented for Ignite to follow suit. Ultimately, if all you want to do is inject some custom JavaScript, that's something you can do within the current Ignite system: add your own language detection code, then redirect as needed. For the tag pages: As I said, my concern is when there's a mismatch between pages that are localized and those that aren't; we'd need to be careful to show only the pages that match the tag in that language, and also need to be careful for places where tags exist in one language but not another. Showing some kind of language selection box would need to take into account that any given page might not actually have a translation available, or might spelled "Artikel" rather than "Articles". We'd likely need to give users some control here (allow mismatched translations? Force matching translations? Some way to link English tag to German equivalent here?), but it's definitely a non-trivial problem that deserves careful thought. |
Alright, I do get your point with websites not always doing the redirection. But Apple, for example, does detect that I'm coming from Germany if I visit apple.com and prominently gives me a button at the top of the page that brings me to apple.de. I also just typed The use case for me would not be restricted to digital products (where I can link to different languages), but also includes physical printings with a link to the apps website, such as on these cards or any QR code I print on paper / stickers. But you said I could "add (my) own language detection code, then redirect as needed". That certainly sounds great. But it's one of the things I didn't understand was possible by the current docs. How is it done? Do I add an Include to every single page that I want to localize? For the tag pages: You are right, giving users some control is not a trivial problem. But for a first version, would you be fine if we only properly supported the "everything is localized" approach? Like I said, the progress percentage indicator in String Catalogs helps detect which languages are missing. For simple websites like app landing pages which only have few languages anyway, this could be a totally viable solution. Or do you want a full-fledged solution from the get to? |
Yes, but are they doing that through IP address or JavaScript locale? Lots of sites use GeoIP or similar, which is why if I visit Microsoft from the UK I get the UK site, but if I enable a VPN in Germany I get the German site – despite using the same computer. The same is true for amd.com, and many others: the source IP address is being read, not the computer's settings.
If you want to include custom JavaScript on every page, the best thing to do is put it directly into a custom theme. This would probably be best expressed as a
For now, I think switching languages to an array then assuming everything is localized is a good step forward – I don't think it would break anything, because we have no localization at all right now and I suspect almost everyone left the setting as the default. So, if someone changes How does that sound?
Again, we need to be very careful here to ensure we don't affect building on Linux and other platforms, so whatever we use to handle localization should be able to work on every platform. Apple renewed their cross-platform push in this year's WWDC SOTU, and when dealing with websites Linux is significantly more commonplace; if we don't strive for cross-platform compatibility I think it will come back to bite us. |
Sounds good to me. 👍 I'll give it a spin later this summer when I work on my app websites.
If there only was a SwiftUI-like UI framework for Linux, I would actually build a String Catalog Editor for Linux platforms. I mean, I already have it all in my app and it's also a 100% free feature, so there's no reason I couldn't create an open-source editor for Linux. If you're thinking about this long term, then I believe a native Linux app written in Swift is the best option. I'm happy to provide a first version once we have a Swift-based UI framework for Linux (much like Ignite is a Swift-based UI framework for the web). Having that said, "dealing with websites Linux is significantly more commonplace" reminds me of where those sites usually are hosted or CI-built on, so I'd like to reiterate that String Catalogs are fully compatible with Linux, it's all just JSON after all, and it's quite human-readable JSON, too. And JSON is editable on Linux without problems. So if I provided a Swift plugin that detected things like |
It seems there are several core tasks here:
Once that's done, we could move on to step 5: update content processing to support localized versions. I've separated that off because it's possible to create Ignite sites entirely without Markdown – just a bunch of static pages, which would require only the first four steps above. |
@twostraws Did you outline those steps for clarity or because you prefer a separate PR for each? I prefer feature-complete PRs that I keep small by limiting the scope. But all 4 steps mentioned would be one PR, I think. I would rephrase the first step to "Support encoding/decoding a subset of the String Catalog JSON format". We don't need to support device-specific variants, I think. (That would require dynamic text loading based on device type.) Likewise, I would also drop pluralization support for version 1. Could be added later if needed. I'll think about the best way to change Currently I'm still focusing on some Post-WWDC work, so I won't be able to immediately start on the localization work here. But I'll probably start sometime in July. I'll let you know of any progress. I'd probably create a WIP PR early, so you can correct me if I go the wrong direction. |
One huge PR would be unwelcome. I'll start on this myself. |
Oh, okay, that's awesome, thank you! 👍 |
Localization is really critical for me. I want to use Ignite to generate my App Help site, and it needs to be localized. Hopefully there is some movement on this. Screenshots need to be grouped into different languages. For the text, the important thing is to have a shared strings file of some sort that can be sent to the translation agency. |
While accessibility labels and ARIA support seem to exist, many statically generated sites like app landing pages or documentation sites would be vastly more accessible if they were available in multiple languages. From what I understand, it would be already possible to create a view with buttons that link to separate subfolders of articles (such as
en
,de-DE
etc.). But there are a few others things that need to be considered for a website with multi-language support:language
value of theSite
based on the current language settings (this line)String
parameters such as for a sitesdescription
or a buttons labelI know that this sounds like adding a dynamic layer to this "static" site generator. Localization in my opinion is for sure a "dynamic" aspect worth providing, but if implemented in a thoughtful manner, we can retain the static aspect by simply creating a duplicate of each page with only the localized texts changed. The language could be provided at root path level via the Language enums raw value, leading to URLs like
https://ignitesamples.hackingwithswift.com/de/grid-examples/
. We could generate variants of all pages for each supported language and place them in the respective folder (e.g.de
) so everything still is static.But we would need some JavaScript to set the
language
value based on the path during page load, so things like the metadata have the correct language set. For things like the usage of localizedContains, while building the different language subfolders, we would need to set a custom locale with the current language being generated for accurate results.As for the string table, I would suggest we use a subset of String Catalogs as we don't need all features, such as "Vary by device". We could even start without pluralization support to keep things simple. I'm happy to donate my
Codable
struct to parse them, which I have already implemented for one of my apps. Updating that is simple enough in case Apple makes changes. It's versioned as well, so we should be able to notice easily. This year, they didn't change anything to the structure, so it should be pretty stable. But I'm happy to adjust the code whenever needed.Using String Catalogs rather than a custom format has great advantages:
String(localized:)
to specify texts that should be localizedLocalizedStringKey
rather thanString
where neededAs not everyone will need or want to localize their sites, we should keep this as opt-in and default to exactly the same behavior without any subpaths like
/en
. Also, a default language should be set and used as a fallback for when a domain is called without any language subpath. I'm not sure if a safe redirect is even possible on static site calls, so the default locale files should just live in the root directory.Please let me know what you think about adding localization support and also about my suggestion. I'm happy to do provide an initial version of localization support once you've approved that what I outlined makes sense to you.
The text was updated successfully, but these errors were encountered: