Skip to content

Commit

Permalink
docs: translate repl (#8)
Browse files Browse the repository at this point in the history
---------
Co-authored-by: 沈青川 <46062972+ShenQingchuan@users.noreply.github.com>
  • Loading branch information
SnowingFox authored Mar 9, 2023
1 parent 1e85989 commit 0ceb9e3
Show file tree
Hide file tree
Showing 30 changed files with 75 additions and 78 deletions.
4 changes: 2 additions & 2 deletions docs/repl/components/BundleOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class="remove"
@click="optionsStore.set(option.name, undefined)"
>
<span class="label">remove</span>
<span class="label">移除</span>
<span class="icon-cancel"></span>
</button>
</h3>
Expand Down Expand Up @@ -57,7 +57,7 @@
$event.target.value = '_';
"
>
<option disabled selected value="_">add option</option>
<option disabled selected value="_">添加设置</option>
<option
v-for="option in optionsStore.additionalAvailableOptions"
:key="option"
Expand Down
4 changes: 2 additions & 2 deletions docs/repl/components/InputHeader.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<header>
<select :value="modulesStore.selectedExample" @input="handleInput">
<option disabled selected value="">Select an example...</option>
<option disabled selected value="">选择一个例子...</option>
<option v-for="(example, id) in examplesById" :key="id" :value="id">
{{ example.title }}
</option>
</select>
<button class="start-over" @click="startOver">Start over</button>
<button class="start-over" @click="startOver">重新开始</button>
</header>
</template>

Expand Down
6 changes: 3 additions & 3 deletions docs/repl/components/OutputStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
>
<span v-if="waiting">
<span class="icon icon-attention"></span>
Loading Rollup...
加载 Rollup...
</span>
<StatusMessage v-else-if="error" :message="error" isError />
<span v-else-if="warnings.length > 0">
<span class="icon icon-attention" />
Rollup completed with warnings:
Rollup 执行完成但出现警告:
<ul class="warning-list">
<li v-for="(warning, i) in warnings" :key="i" class="warning">
<StatusMessage :message="warning" />
Expand All @@ -19,7 +19,7 @@
</span>
<span v-else>
<span class="icon icon-ok"></span>
Rollup successful!
Rollup 执行成功!
</span>
</div>
</template>
Expand Down
2 changes: 1 addition & 1 deletion docs/repl/components/ReplInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<button class="new-module" @click="createModule">
<span class="icon icon-plus"></span>
add module
添加模块
</button>
</template>

Expand Down
6 changes: 3 additions & 3 deletions docs/repl/components/ReplMain.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<template>
<div class="repl">
<div class="left">
<h2>ES6 modules go in...</h2>
<h2>ES6 模块进入...</h2>
<div class="input">
<ReplInput />
</div>
</div>
<div class="right">
<h2>
...
{{ rollupOutputStore.output.length > 1 ? 'chunks come' : 'bundle comes' }}
out
{{ rollupOutputStore.output.length > 1 ? '产出分块' : '产出包' }}
输出
</h2>
<div class="output">
<ReplOutput />
Expand Down
6 changes: 3 additions & 3 deletions docs/repl/components/ReplModule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
<span v-if="editableHeader">
<input ref="input" v-model="module.name" @focus="selectName" placeholder="foo.js" />
<button class="remove" @click="emit('remove')">
<span class="label">remove</span>
<span class="label">移除</span>
<span class="icon-cancel"></span>
</button>
<button class="toggle-entry" @click="module.isEntry = !module.isEntry">
<span class="label">(entry&nbsp;module)</span>
<span class="label">(入口&nbsp;模块)</span>
<span v-if="module.isEntry" class="icon-minus"></span>
<span v-else class="icon-plus"></span>
</button>
</span>
<span v-else-if="showHeader" class="module-name">
{{ module.name }}
<span v-if="module.isEntry" class="entry-module-label">(entry module)</span>
<span v-if="module.isEntry" class="entry-module-label">(入口模块)</span>
</span>
</header>
<ReplEditor v-model:code="module.code" :moduleName="module.name" :readonly="!editable" />
Expand Down
10 changes: 4 additions & 6 deletions docs/repl/components/RollupVersion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ const version = computed(() => {
const { type, version } = rollupStore.request;
const actualVersion = rollupStore.loaded.instance?.VERSION;
if (type === 'local') {
return actualVersion
? `Local development build (${actualVersion})`
: 'Loading local development build …';
return actualVersion ? `本地开发构建 (${actualVersion})` : '加载本地开发构建中 …';
}
if (type === 'pr') {
return actualVersion
? `Pull request ${getPRLink(version)} (${actualVersion})`
: `Loading pull request ${getPRLink(version)} …`;
? `拉取请求 ${getPRLink(version)} (${actualVersion})`
: `加载拉取请求中 ${getPRLink(version)} …`;
}
return actualVersion
? `Rollup ${getVersionLink(actualVersion)}`
: `Loading Rollup ${version || '(latest)'} …`;
: `加载 Rollup ${version || '(latest)'} …`;
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion docs/repl/examples/00/example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "Tree-shaking",
"title": "除屑优化(Tree-shaking",
"options": {
"treeshake": true
}
Expand Down
2 changes: 1 addition & 1 deletion docs/repl/examples/00/modules/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// TREE-SHAKING
// 除屑优化
import { cube } from './maths.js';

console.log(cube(5)); // 125
18 changes: 9 additions & 9 deletions docs/repl/examples/00/modules/maths.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// maths.js

// This function isn't used anywhere, so
// Rollup excludes it from the bundle...
// 这个函数并没有被外部模块使用
// 所以 Rollup 会将它从打包产物中排除掉...
export const square = x => x * x;

// This function gets included
// rewrite this as `square(x) * x`
// and see what happens!
// 这个函数被外部模块使用了
// 把这个函数重写为 `square(x) * x`
// 看看会发生什么。
export const cube = x => x * x * x;

// This "side effect" creates a global
// variable and will not be removed.
// 这个“副作用”创建了一个全局变量
// 所以它不会被移除。
window.effect1 = 'created';

const includeEffect = false;
if (includeEffect) {
// On the other hand, this is never
// executed and thus removed.
// 另一方面来说,这将永远不会被执行
// 所以会被移除。
window.effect1 = 'not created';
}
2 changes: 1 addition & 1 deletion docs/repl/examples/01/example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "Named exports",
"title": "具名导出(Named exports",
"options": {
"output": {
"exports": "auto",
Expand Down
10 changes: 5 additions & 5 deletions docs/repl/examples/01/modules/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// NAMED EXPORTS
// There are many ways to export bindings
// from an ES2015 module
// 具名导出
// 有很多种方法可以从 ES2015 模块中
// 导出绑定
export var foo = 1;

export function bar() {
// try changing this to `foo++`
// when generating CommonJS
// 在生成 CommonJS 时
// 尝试将此更改为 `foo++`
return foo;
}

Expand Down
2 changes: 1 addition & 1 deletion docs/repl/examples/02/example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "Default exports",
"title": "默认导出(Default exports",
"options": {
"output": {
"exports": "auto",
Expand Down
4 changes: 2 additions & 2 deletions docs/repl/examples/02/modules/answer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Internal default exports are turned
// into variables
// 内部默认导出会被
// 转换为变量
export default 42;
5 changes: 2 additions & 3 deletions docs/repl/examples/02/modules/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// DEFAULT EXPORTS
// Default exports from the 'entry module' are
// exported from the bundle
// 默认导出
// 从“入口模块”默认导出的内容会被打包后导出
import answer from './answer.js';

export default () => console.log('the answer is ' + answer);
2 changes: 1 addition & 1 deletion docs/repl/examples/03/example.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"title": "Static namespaces"
"title": "静态名称空间"
}
10 changes: 5 additions & 5 deletions docs/repl/examples/03/modules/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// STATIC NAMESPACES
// ES6 modules let you import all of another module's
// exports as a namespace...
// 静态名称空间
// ES6 模块允许你
// 将另一个模块的所有导出都作为命名空间导入...
import * as assert from './assert';

// ...but we can statically resolve this to the
// original function definition
// ...但我们可以静态地
// 将其解析为原始函数定义
assert.equal(1 + 1, 2);
2 changes: 1 addition & 1 deletion docs/repl/examples/04/example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "Dynamic namespaces",
"title": "动态名称空间",
"options": {
"output": {
"freeze": "true"
Expand Down
10 changes: 5 additions & 5 deletions docs/repl/examples/04/modules/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// DYNAMIC NAMESPACES
// In some cases, you don't know which exports will
// be accessed until you actually run the code. In
// these cases, Rollup creates a namespace object
// for dynamic lookup
// 动态名称空间
// 在某些情况下
// 直到实际运行代码之前,你不知道哪些代码块将会被导出。
// 在这些情况下
// Rollup 会创建一个用于动态查找的命名空间对象
import * as constants from './constants';

for (const key of Object.keys(constants)) {
Expand Down
2 changes: 1 addition & 1 deletion docs/repl/examples/05/example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "External imports",
"title": "外部导入",
"options": {
"output": {
"globals": {
Expand Down
6 changes: 3 additions & 3 deletions docs/repl/examples/05/modules/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// EXTERNAL IMPORTS
// You can import external modules into your bundle –
// it doesn't matter if they're ES2015 or legacy
// 外部导入
// 您可以将外部模块导入到你的打包产物中 -
// 不用在意那些代码是 ES 模块还是其他兼容格式
import $ from 'jquery';

$('body').html('<h1>Hello world!</h1>');
2 changes: 1 addition & 1 deletion docs/repl/examples/06/example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "Dynamic imports",
"title": "动态导入",
"options": {
"output": {
"inlineDynamicImports": false
Expand Down
12 changes: 6 additions & 6 deletions docs/repl/examples/06/modules/main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// DYNAMIC IMPORTS
// Rollup supports automatic chunking and lazy-loading
// via dynamic imports utilizing the import mechanism
// of the host system.
// 动态导入
// Rollup 支持通过动态导入
// 利用系统的导入机制
// 进行自动分块和延迟加载。
import square from './square.js';

// Directly use some math
// 直接使用一些数学方法
console.log(square(2));

// Dynamically import the rest
// 动态导入其余部分
import('./maths.js').then(maths => {
console.log(maths.square(5));
console.log(maths.cube(5));
Expand Down
4 changes: 2 additions & 2 deletions docs/repl/examples/06/modules/square.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Modules shared between the entry chunk and the
// dynamic chunk are merged into the entry chunk.
// 在入口块和动态块之间共享的模块
// 将合并到入口块中。
export default x => x * x;
4 changes: 2 additions & 2 deletions docs/repl/examples/07/example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "Multiple Entry Modules",
"entryModules": ["main.js", "otherEntry.js"],
"title": "多个入口模块",
"entryModules": ["main.js", "otherEntry.js"],
"options": {
"output": {
"minifyInternalExports": false,
Expand Down
6 changes: 3 additions & 3 deletions docs/repl/examples/07/modules/cube.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import square from './square.js';

// Everything used by both entry modules will become
// a separate chunk that is imported by both entry
// chunks to avoid code duplication
// 两个入口模块都使用的所有内容都将成为一个单独的代码块,
// 由两个入口代码块导入
// 以避免代码重复
export default function cube(x) {
return square(x) * x;
}
4 changes: 2 additions & 2 deletions docs/repl/examples/07/modules/hyperCube.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cube from './cube.js';

// This is only imported by one entry module and
// shares a chunk with that module
// 这只被一个入口模块导入
// 并与该模块共享一个代码块
export default function hyperCube(x) {
return cube(x) * x;
}
2 changes: 1 addition & 1 deletion docs/repl/examples/07/modules/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MULTIPLE ENTRY MODULES
// 多个入口模块
import hyperCube from './hyperCube.js';

console.log(hyperCube(5));
2 changes: 1 addition & 1 deletion docs/repl/examples/07/modules/otherEntry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Additional entry modules create new chunks
// 额外的入口模块会创建新的代码块。
import cube from './cube.js';

console.log(cube(5));
2 changes: 1 addition & 1 deletion docs/repl/examples/07/modules/square.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This is also shared between the entry chunks
// 这也在入口代码块之间共享。
export default function square(x) {
return x * x;
}

0 comments on commit 0ceb9e3

Please sign in to comment.