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

Implementation of the Link Decorator function for processing localised links πŸˆ‚οΈ #47620

Merged
merged 1 commit into from
Aug 24, 2024

Conversation

Andygol
Copy link
Contributor

@Andygol Andygol commented Aug 21, 2024

Description

I'm pleased to introduce the Link Decorator feature, which automatically transforms links in localised documents if the referenced documents have been localised. This feature eliminates the need to manually add language codes to links.

This was also inspired by the https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/_markup/render-link.html template, which is already included in Hugo.

The logic is as follows

graph LR;

src_link("Link in a doc…")


src_link-->none_localized_link("… is not localized starts with /…")-->
check_for_localization{"if a localized
doc exists"}-- "yes, it is" -->add_lng_prefix("Add lang-code prefix to the link")

src_link-->indoc_link("… is in the same doc starts with # symbol")
src_link-->already_localized_link("… is already localized starts with /lang-code/…")
src_link-->ext_link("…is an external link starts with protocol [https:|mailto:|…] ")

ext_link & already_localized_link & indoc_link ---> asis("Keep it as is")
check_for_localization-- "no, it isn't" -->asis
Loading

The current approach fully implements the logic of link decoration by adding a language prefix to localised documents where it is not explicitly specified. Links with a hard-coded https://kubernetes.io/ or https://k8s.io/ are considered external and processed as such, even if there are localised versions of the link in the documentation. Handling such cases significantly complicates the code and processing time, and it is easier to correct such links directly in the text of documents.

I hope that the adoption of this PR will significantly improve the usability of the documentation and simplify the work of translators to maintain it.

Issue

This effort was inspired by a previous discussion about adding language code manually when localising documents.Β β€” #18403

/hold Depends on: PR #47612 β€” Fixed flag deprecations and updated Hugo version to latest

/cc @sftim as per your request in Slack.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 21, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/docs Categorizes an issue or PR as relevant to SIG Docs. labels Aug 21, 2024
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 21, 2024
Copy link

netlify bot commented Aug 21, 2024

βœ… Pull request preview available for checking

Built without sensitive environment variables

Name Link
πŸ”¨ Latest commit a0ede94
πŸ” Latest deploy log https://app.netlify.com/sites/kubernetes-io-main-staging/deploys/66c6621707d88000089741b0
😎 Deploy Preview https://deploy-preview-47620--kubernetes-io-main-staging.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@tengqm
Copy link
Contributor

tengqm commented Aug 21, 2024

Some clarifications:

  • This code automagically works without having to revise any existing English pages, right?
  • The existing language prefix added by localization teams still works with this code, right?
  • The fallback to English page is transparent, right?
  • Any statistics about the build time after introducing this code?

@Andygol
Copy link
Contributor Author

Andygol commented Aug 22, 2024

Some clarifications:

  • This code automagically works without having to revise any existing English pages, right?
  • The existing language prefix added by localization teams still works with this code, right?
  • The fallback to English page is transparent, right?
  • Any statistics about the build time after introducing this code?

@tengqm
Absolutely, all already localized links works; in case you've referred translated documents but do not add language prefix explicitly, it will be added by decorator; if there's absent localized link, language code won't be added. After merging this PR manual addition of language codes will be deprecated. You may check Chinese test page https://deploy-preview-47620--kubernetes-io-main-staging.netlify.app/zh-cn/docs/test/.

See netlify response above to find build log.

UPD. The true functionality of this code can only be assessed after the Hugo is updated to the up-to-date version, see PR #47612.

@sftim
Copy link
Contributor

sftim commented Aug 22, 2024

/area web-development

Nice to see this arrive!

@k8s-ci-robot k8s-ci-robot added the area/web-development Issues or PRs related to the kubernetes.io's infrastructure, design, or build processes label Aug 22, 2024
@Andygol
Copy link
Contributor Author

Andygol commented Aug 23, 2024

/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 23, 2024
@Andygol
Copy link
Contributor Author

Andygol commented Aug 23, 2024

As PR #47612 has been merged, feel free to review and approve this one as wellπŸ™

@Andygol
Copy link
Contributor Author

Andygol commented Aug 23, 2024

Re-run test to engage new build with updated Hugo
/test all

@k8s-ci-robot
Copy link
Contributor

@Andygol: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

Re-run test to engage new build with updated Hugo
/test all

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@sftim
Copy link
Contributor

sftim commented Aug 23, 2024

(aside) This repo does not really use Prow's /test command.

@Andygol
Copy link
Contributor Author

Andygol commented Aug 24, 2024

(aside) This repo does not really use Prow's /test command.

πŸ™„ It would be great to re-engage netlify build process somehow to streamline review.

@tengqm
Copy link
Contributor

tengqm commented Aug 24, 2024

The only concern from me is about the build time overhead (supposing that all conversions are done during build time). However, as a standalone processor, we can easily disable it if it goes wrong.
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tengqm

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 24, 2024
@Andygol
Copy link
Contributor Author

Andygol commented Aug 24, 2024

Should anyone from sig-docs-website-owners add LGTM?

@steve-hardman
Copy link
Contributor

Looks like a nice addition to help the localization teams.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 24, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: d4effeeaf0186ad7a597d0d48a2120c621b36ea2

@k8s-ci-robot k8s-ci-robot merged commit 81e1083 into kubernetes:main Aug 24, 2024
6 checks passed
@sftim
Copy link
Contributor

sftim commented Aug 27, 2024

It would be great to re-engage netlify build process somehow to streamline review.

PRs welcome (from anyone)! But it's not a priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/web-development Issues or PRs related to the kubernetes.io's infrastructure, design, or build processes cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants