@@ -250,31 +250,53 @@ into a platform interface, independent platform implementations
250250of that interface, and an app-facing interface that uses the
251251registered implementation of the running platform.
252252
253+ ** 联合插件** 是一种将插件的 API 拆分为平台接口、该接口的独立平台实现以及使用运行平台注册实现的面向应用的接口的方式。
254+
253255** Package-separated federated plugins** are federated plugins where
254256the platform interface, platform implementations, and the app-facing
255257interface are all separated into their own Dart packages.
256258
259+ ** Package 分离的联合插件** 是指平台接口、平台实现和面向应用的接口都分离到各自的 Dart package 中的联合插件。
260+
257261So, a package-separated federated plugin can use one package for iOS,
258262another for Android, another for web,
259263and yet another for a car (as an example of an IoT device).
260264Among other benefits, this approach allows a domain expert
261265to extend an existing plugin to work for the platform they know best.
262266
267+ 因此,一个 package 分离的联合插件可以使用一个 package 用于 iOS,
268+ 另一个用于 Android,再一个用于 web,
269+ 甚至另一个用于汽车(作为物联网设备的示例)。
270+ 除了其他好处之外,这种方法允许领域专家扩展现有插件,使其适用于他们最熟悉的平台。
271+
263272A federated plugin requires the following:
264273
274+ 插件插件需要以下内容:
275+
265276** app-facing interface**
266277<br > The interface that plugin users interact with when using the
267278 plugin. This interface specifies the API used by the Flutter app.
268279 In a package-separated federated plugin, this is the package
269280 that plugin users depend on to use the plugin.
270281
282+ ** 面向应用的接口**
283+ <br > 插件用户在使用插件时与之交互的接口。
284+ 此接口指定了 Flutter 应用使用的 API。
285+ 在 package 分离的联合插件中,
286+ 这是插件用户依赖的 package,用于使用该插件。
287+
271288** platform implementation(s)**
272289<br > One or more implementations that contain the platform-specific
273290 implementation code. The app-facing interface calls into
274291 these implementations&mdash ; they aren't directly used, or
275292 depended on when package-separated, in an app unless they contain
276293 platform-specific functionality accessible to the end user.
277294
295+ ** 平台实现**
296+ <br > 一个或多个包含平台特定实现代码的实现。
297+ 面向应用的接口会调用这些实现——它们不会在应用中直接使用,
298+ 或者在 package 分离时直接依赖,除非它们包含最终用户可访问的平台特定功能。
299+
278300** platform interface**
279301<br > The interface that glues the app-facing interface
280302 to the platform implementations(s). This declares an
@@ -283,6 +305,11 @@ A federated plugin requires the following:
283305 that defines this interface ensures that all platform
284306 packages implement the same functionality in a uniform way.
285307
308+ ** 平台接口**
309+ <br > 将面向应用的接口与平台实现连接起来的接口。
310+ 它声明了一个接口,任何平台实现都必须实现该接口才能支持面向应用的接口。
311+ 拥有一个单独的 package 来定义此接口可确保所有平台 package 以统一的方式实现相同的功能。
312+
286313#### Endorsed federated plugin
287314
288315#### 整合的联合插件
@@ -322,6 +349,11 @@ is _not_ endorsed. A developer can still use your
322349implementation, but must manually add the plugin
323350to the app's ` pubspec.yaml ` file:
324351
352+ 如果你因任何原因无法让原始插件作者添加你的实现,
353+ 那么你的插件 ** 不** 受认可。
354+ 开发者仍然可以使用你的实现,
355+ 但必须手动将插件添加到应用的 ` pubspec.yaml ` 文件中:
356+
325357``` yaml
326358dependencies :
327359 foobar : ^1.0.0
@@ -731,16 +763,28 @@ You can run the example app by pressing the run (▶) button.
731763
732764# #### Add native Darwin dependencies (Swift Package Manager)
733765
766+ # #### 添加原生 Darwin 依赖 (Swift Package Manager)
767+
734768Flutter uses Swift Package Manager as the primary strategy to manage
735769native iOS and macOS dependencies.
736770
771+ Flutter 使用 Swift Package Manager 作为管理原生 iOS 和 macOS 依赖的主要策略。
772+
737773To add a dependency to your plugin using Swift Package Manager :
738774
775+ 要使用 Swift Package Manager 为你的插件添加依赖:
776+
7397771. Create a `Package.swift` file in your plugin's `ios/my_plugin_name`
740778 or `macos/my_plugin_name` directory.
779+
780+ 创建一个 `Package.swift` 文件,
781+ 位于你插件的 `ios/my_plugin_name` 或 `macos/my_plugin_name` 目录中。
782+
7417832. Declare your native dependency within the `dependencies` array of the
742784 `Package.swift` descriptor file :
743785
786+ 在 `Package.swift` 描述符文件的 `dependencies` 数组中声明你的原生依赖:
787+
744788` ` ` swift title="Package.swift"
745789dependencies: [
746790 .package(url: "https://github.com/path/to/HelloLibrary.git", from: "1.0.0")
@@ -751,22 +795,33 @@ For complete details and instructions on structuring native folders, resource
751795bundling, or handling hybrid setups,
752796visit the [Swift Package Manager for plugin authors][] guide.
753797
798+ 有关原生文件夹结构、资源打包或处理混合设置的完整详细信息和说明,
799+ 请访问 [适用于插件作者的 Swift Package Manager][Swift Package Manager for plugin authors] 指南。
800+
754801[Swift Package Manager for plugin authors] : /packages-and-plugins/swift-package-manager/for-plugin-authors
755802
756803# #### Add CocoaPod dependencies (legacy)
757804
805+ # #### 添加 CocoaPod 依赖 (旧版)
806+
758807Flutter continues to support CocoaPods for backward compatibility. If your
759808plugin needs to support developers who haven't migrated to Swift Package
760809Manager yet, specify your CocoaPods dependency at the end of
761810`ios/hello.podspec` :
762811
812+ Flutter 继续支持 CocoaPods 以实现向后兼容。
813+ 如果你的插件需要支持尚未迁移到 Swift Package Manager 的开发者,
814+ 请在 `ios/hello.podspec` 的末尾指定你的 CocoaPods 依赖:
815+
763816` ` ` ruby
764817s.dependency 'HelloPod', '0.0.1'
765818` ` `
766819
767820For private pods, refer to
768821[Private CocoaPods][] to ensure repo access :
769822
823+ 对于私有 pod,请参阅 [私有 CocoaPods][Private CocoaPods] 以确保仓库访问:
824+
770825` ` ` ruby
771826s.source = {
772827 # For pods hosted on GitHub
@@ -781,24 +836,38 @@ s.source = {
781836
782837# #### Installing the plugin dependencies
783838
839+ # #### 安装插件依赖
840+
784841To fetch and link the plugin's dependencies, add the plugin to your app project's
785842` pubspec.yaml` dependencies, and run `flutter pub get`. Flutter automatically
786843resolves and wires up the Swift Package Manager descriptors or CocoaPods
787844pod files during the native app build step.
788845
846+ 要获取并链接插件的依赖,
847+ 请将插件添加到你的应用项目的 `pubspec.yaml` 依赖中,然后运行 `flutter pub get`。
848+ Flutter 会在原生应用构建步骤中自动解析并连接 Swift Package Manager 描述符或 CocoaPods pod 文件。
849+
789850If your plugin requires a privacy manifest, for example,
790851if it uses any **required reason APIs**,
791852update the `PrivacyInfo.xcprivacy` file to
792853describe your plugin's privacy impact,
793854and add the following to the bottom of your podspec file :
794855
856+ 如果你的插件需要隐私清单,
857+ 例如,如果它使用了任何 **required reason API**,
858+ 请更新 `PrivacyInfo.xcprivacy` 文件以描述你的插件的隐私影响,
859+ 并将以下内容添加到你的 podspec 文件底部:
860+
795861` ` ` ruby
796862s.resource_bundles = {'your_plugin_privacy' => ['your_plugin/Sources/your_plugin/Resources/PrivacyInfo.xcprivacy']}
797863` ` `
798864
799865For more information,
800866check out [Privacy manifest files][] on the Apple developer site.
801867
868+ 想要了解更多信息,
869+ 请查看 Apple 开发者网站上的 [隐私清单文件][Privacy manifest files]。
870+
802871[Privacy manifest files] : {{site.apple-dev}}/documentation/bundleresources/privacy_manifest_files
803872
804873# ### Step 2d: Add Linux platform code (.h+.cc)
@@ -913,22 +982,40 @@ You can run the example app by pressing the run (▶) button.
913982
914983We recommend you edit the Windows code using Visual Studio.
915984
985+ 我们建议你使用 Visual Studio 编辑 Windows 代码。
986+
916987Before editing the Windows platform code in Visual Studio,
917988first make sure that the code has been built at least once
918989(in other words, run the example app from your IDE/editor,
919990or in a terminal execute
920991` cd hello/example; flutter build windows` ).
921992
993+ 在 Visual Studio 中编辑 Windows 平台代码之前,
994+ 请首先确保代码至少构建过一次
995+ (换句话说,从你的 IDE/编辑器运行示例应用,
996+ 或在终端中执行 `cd hello/example; flutter build windows`)。
997+
922998Then use the following steps :
923999
1000+ 然后使用以下步骤:
1001+
92410021. Launch Visual Studio.
1003+
1004+ 启动 Visual Studio。
1005+
92510061. Select **Open a project or solution**, and select the
9261007 ` hello/example/build/windows/hello_example.sln` file.
9271008
1009+ 选择 **Open a project or solution**,
1010+ 然后选择 `hello/example/build/windows/hello_example.sln` 文件。
1011+
9281012The Windows platform code for your plugin is located in
9291013` hello_plugin/Source Files` and `hello_plugin/Header Files` in
9301014the Solution Explorer.
9311015
1016+ 你插件的 Windows 平台代码位于解决方案资源管理器中的
1017+ ` hello_plugin/Source Files` 和 `hello_plugin/Header Files`。
1018+
9321019You can run the example app by right-clicking `hello_example` in
9331020the Solution Explorer and selecting **Set as Startup Project**,
9341021then pressing the run (▶) button. **Important:** After
@@ -937,8 +1024,16 @@ making changes to plugin code, you must select
9371024an outdated copy of the built plugin will be run instead
9381025of the latest version containing your changes.
9391026
1027+ 你可以通过右键单击解决方案资源管理器中的 `hello_example` 并选择 **Set as Startup Project**,
1028+ 然后按下运行 (▶) 按钮来运行示例应用。
1029+ **重要提示:** 在更改插件代码后,
1030+ 你必须在再次运行之前选择 **Build > Build Solution**,
1031+ 否则将运行构建的插件的过时副本,而不是包含你的更改的最新版本。
1032+
9401033# ### Step 2g: Connect the API and the platform code
9411034
1035+ # ### 步骤 2g:连接 API 和平台代码
1036+
9421037Finally, you need to connect the API written in Dart code with
9431038the platform-specific implementations.
9441039This is done using a [platform channel][],
@@ -1167,9 +1262,12 @@ they are generated from the header file
11671262Reference the [ffigen docs][] for information
11681263on how to install this package.
11691264
1265+ 为了避免手动编写这些内容,
1266+ 它们由 [`package:ffigen`][] 从头文件 (`src/hello.h`) 生成。
1267+ 有关如何安装此 package 的信息,请参阅 [ffigen 文档][ffigen docs]。
1268+
11701269To regenerate the bindings, run the following command :
11711270
1172- 为了避免手工编写,它们由头文件 (`src/hello.h`) 中的 [`package:ffigen`][] 生成。
11731271运行以下指令重新生成绑定:
11741272
11751273` ` ` console
@@ -1437,6 +1535,7 @@ $ flutter pub publish
14371535` ` `
14381536
14391537:::note
1538+
14401539设置了中国镜像的开发者们请注意:
14411540目前所存在的镜像都不能(也不应该)进行 package 的上传。
14421541如果你设置了镜像,执行上述发布代码可能会造成发布失败。
@@ -1445,6 +1544,7 @@ $ flutter pub publish
14451544` ` ` console
14461545$ flutter pub publish --server=https://pub.dartlang.org
14471546` ` `
1547+
14481548:: :
14491549
14501550For more details on publishing, see the
@@ -1556,10 +1656,12 @@ file, like any other Dart package.
15561656所有的 Web 依赖都由文件 `pubspec.yaml` 来处理。
15571657
15581658{% comment %}
1659+
15591660<!-- Remove until we have better text. -->
15601661# ## MacOS
15611662
15621663PENDING
1664+
15631665{% endcomment %}
15641666
15651667[bind-native] : /platform-integration/bind-native-code
0 commit comments