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

[5.0] i18n rebuild #13038

Merged
merged 15 commits into from
Jul 30, 2020
Merged

[5.0] i18n rebuild #13038

merged 15 commits into from
Jul 30, 2020

Conversation

wf123537200
Copy link
Contributor

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Refactor the i18n solution

Fixed issues

#12926

Details

Before: What was the problem?

i18n depends on packaging solution

After: How is it fixed in this PR?

as No.9 in the #12926 , refactor the i18n solution

Usage

Are there any API changes?

  • The API has been changed.

add the method as

echarts.registerLocale('ES', lang);

add the params in the echarts.init as

echarts.init(document.getElementById('main3'), null, {
            locale: 'ES'
        });

Related test cases or examples to use the new APIs

lang.html

Others

Merging options

  • Please squash the commits into a single one when merge.

Other information

need to be done:
1、review the i18n solution is right
2、delete lang packaging code
3、check the test case is cover all the situation

@echarts-bot
Copy link

echarts-bot bot commented Jul 29, 2020

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

@@ -92,6 +92,9 @@ import { getVisualFromData, getItemVisualFromData } from './visual/helper';
import LabelManager from './label/LabelManager';
import { deprecateLog } from './util/log';
import { handleLegacySelectEvents } from './legacy/dataSelectAction';
// default import ZH and EN lang
import langEN from "../i18n/langEN";
import langZH from "../i18n/langZH";

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to put builtin langEN and langZH in the src/i18n. To keep all the source files in src folder. Or it may have unexpected issues when bundling. For examples, typescript compiler will check if the files are in the root src folder.

factory({});
}
})(this, function(exports) {
var lang =`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems there is no export here.

Also obj export is not convenient in the case which loads script with HTML tag. I think we can keep it simple and only use CommonJS exports for the -obj files.

Copy link
Contributor Author

@wf123537200 wf123537200 Jul 29, 2020

Choose a reason for hiding this comment

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

the exports code at the L54 like

 const pureExports = `
            exports.lang = lang;
        `;

localeStorage['EN'] = localeStorage['EN'] || langEN;
this._locale = typeof locale === 'string' ? localeStorage[locale] : zrUtil.clone(locale);
console.log(this._locale)

Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to remove console.log here

src/echarts.ts Outdated
export function registerLocale(name: string, locale: LocaleOption): void {
localeStorage[name] = locale;
console.log('localeStorage', localeStorage);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to remove console.log here

const locale = this.getLocale()
let localeText: string | any;
localePosition.map(t => {
localeText = localeText ? localeText[t] : locale[t];
Copy link
Contributor

Choose a reason for hiding this comment

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

localePosition can also be wrapped with a Model to do deep query.

For example:

const localeModel = this.getLocaleModel();
const localeText = localeModel.get(localePosition);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I didn't quite understand what to do.
Should we add a method as getLocaleModel for user to get the model of locale?

})

if(localeHandlerFn) {
localeText = localeHandlerFn(localeText);
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra space after '=' here.

Also, I'm not sure the last parameter localeHandleFn is necessary. It will increase the complexity of using this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sometimes the text may handle after get,for example:

lang: ecModel.getWithLocale(['toolbox', 'saveAsImage', 'lang'], null, (t) => t.slice())

the toolebox.saveAsImage.lang is an array but need to be slice() after gotten.

package.json Outdated Show resolved Hide resolved
src/component/toolbox/feature/MagicType.ts Outdated Show resolved Hide resolved
src/echarts.ts Outdated Show resolved Hide resolved
src/model/Global.ts Outdated Show resolved Hide resolved
src/model/Global.ts Outdated Show resolved Hide resolved
@wf123537200 wf123537200 mentioned this pull request Jul 29, 2020
@@ -31,6 +31,7 @@ import {
CommonTooltipOption,
Dictionary
} from '../../util/types';
import GlobalModel from "../../model/Global";
Copy link
Member

Choose a reason for hiding this comment

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

Note that we should use ' but not ", check everywhere and correct them, please.

Copy link
Contributor

Choose a reason for hiding this comment

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

@plainheart Thanks for the detailed review. I just fixed it

@pissang pissang merged commit f300e10 into next Jul 30, 2020
@echarts-bot
Copy link

echarts-bot bot commented Jul 30, 2020

Congratulations! Your PR has been merged. Thanks for your contribution! 👍

@pissang pissang deleted the next-i18n branch August 16, 2020 08:44
@pissang pissang changed the title i18n rebuild [5.0] i18n rebuild Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants