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

Fix bug wrong metadata on translated docs #709

Closed
wants to merge 3 commits into from

Conversation

gimdongwoo
Copy link
Contributor

@gimdongwoo gimdongwoo commented May 29, 2018

Motivation

There is a bug where metadata files are generated incorrectly when using multilingual features.

When processMetadata function is called in translated_docs, the logic to determine the multilingual language has bug.

We already knew the language so We did not have to do it twice.

[Incorrect - core/metadata.js]
The language is reversed (en - ko).
2018-05-29 4 27 43

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

using multilingual features.

[Correct - core/metadata.js]
2018-05-29 4 39 13

Related PRs

e273dfc#diff-a6ea8ce8e7c294d50b747139bc956138

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label May 29, 2018
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented May 29, 2018

Deploy preview for docusaurus-preview ready!

Built with commit 45f16c8

https://deploy-preview-709--docusaurus-preview.netlify.com

let regexSubFolder = new RegExp(
'/' + escapeStringRegexp(getDocsPath()) + '/(.*)/.*/'
);
let language = _language;
Copy link
Contributor

@endiliey endiliey May 29, 2018

Choose a reason for hiding this comment

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

why don't we delete this proposed line 128 and replace _language at proposed line 125 to be language
Save one line of code ? 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This 3 lines is moved to the next line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the code is not needed in this situations if language is given.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean

function processMetadata(file, language) {

instead of

function processMetadata(file, _language) {
let language = _language;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think no-param-reassign is good code style.
https://eslint.org/docs/rules/no-param-reassign

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course if you want to change it, I will change it. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually had that doubt as well. I'll leave it to @yangshun & @JoelMarcey to decide ☺

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Please make the corrections that @endiliey suggested.

Copy link
Contributor Author

@gimdongwoo gimdongwoo left a comment

Choose a reason for hiding this comment

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

Done :)

let regexSubFolder = new RegExp(
'/' + escapeStringRegexp(getDocsPath()) + '/(.*)/.*/'
);
let language = _language;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the code is not needed in this situations if language is given.

let regexSubFolder = new RegExp(
'/' + escapeStringRegexp(getDocsPath()) + '/(.*)/.*/'
);
let language = _language;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think no-param-reassign is good code style.
https://eslint.org/docs/rules/no-param-reassign

let regexSubFolder = new RegExp(
'/' + escapeStringRegexp(getDocsPath()) + '/(.*)/.*/'
);
let language = _language;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course if you want to change it, I will change it. :)

@@ -271,7 +273,7 @@ function generateMetadataDocs() {
const extension = path.extname(file);

if (extension === '.md' || extension === '.markdown') {
const res = processMetadata(file);
const res = processMetadata(file, language);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you want to pass language in to the other calls to processMetadata?

e.g., on line 219 in this file:

const res = processMetadata(file);

Copy link
Contributor Author

@gimdongwoo gimdongwoo Jun 4, 2018

Choose a reason for hiding this comment

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

We only need to specify the language case, if we use translated_docs. In general, we do not need to specify, because we use getDocsPath. It seems to increase unnecessary processing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @gimdongwoo - In general though, I don't like leaving a parameter missing to a function call. It can cause confusion in reading the code. Even if you don't pass language -- which I still think is ok - can you pass something, even if a ''?

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

Please refer to Joel's comment regarding line 219

@gimdongwoo
Copy link
Contributor Author

gimdongwoo commented Jun 4, 2018

I know a lot more bugs related to this project's multilingual, and I was fixed it already. However, there are many cases where we need to change the structure a lot, so I want to send PR in gradually.

I do not think nobody actually using this project as a multilingual environment. Even React Native documents are not available in multiple languages.

@JoelMarcey
Copy link
Contributor

I know a lot more bugs related to this project's multilingual

😮

What are some of these bugs?

@endiliey
Copy link
Contributor

endiliey commented Jun 4, 2018

Https://reasonml.github.io use multi language support.

I think its best for @gimdongwoo to let us know on these bugs 😊

Anyway, i actually found out about this bug too when working on subdirectories, athough it will be fixed on #705.
We use processMetadataFile for docs & translated docs and they have a structure like
docs/:language/:filename.md and translated_docs/:language/:filename.md

@mattkanwisher
Copy link

We are running our docs in 3 languages and hope to support 2 more. So I don't believe its true that no one is running multilingual. http://loomx.io/developers

@mattkanwisher
Copy link

This largely fixes our issues in the sidebar with Japanese and Chinese language seeping into the English docs

@endiliey
Copy link
Contributor

endiliey commented Jun 4, 2018

Oh I saw that @mattkanwisher. Chinese meta in your english docs
saw it

@yangshun
Copy link
Contributor

yangshun commented Jun 7, 2018

Closed in favor of #705

@yangshun yangshun closed this Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants