NX Monorepo(14.3.6)不支持$局部化(Angular局部)

发布于 2025-02-09 17:56:29 字数 1196 浏览 1 评论 0原文

这是我安装了最新版本的NX MonorePo(NPX Create-NX-Workspace@最新)。 NX的当前最新版本为(14.3.6)。之后,我添加了Angular本地化软件包(npm install @angular/bentize)。此时,添加i18n属性(<标题I18n> title</title>)工作正常,并且将转换密钥提取到message.xlf文件中。

问题是,如果我尝试在这种情况下使用$本地化$局部化,则没有报告任何错误,但是当我尝试生成消息时,使用> ng extract-i18n test-app。生成一个空的消息。xlf。

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = $localize`my-app`;
}

Messages.xlf

<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
  <file source-language="en-US" datatype="plaintext" original="ng2.template">
    <body>
    </body>
  </file>
</xliff>

因此,问题是否支持NX Monorepo中的$本地化? 也许项目中缺少某些配置。

我在这里添加了一个链接到GitHub( https://github.com/github.com/hivaga/nx--nx--nx---可以找到当前NX设置的定位支持)。

PS我尝试了最新的香草角度应用程序设置,那里的本地化作品是预期的,因此显然问题仅在NX方面!

Here is the case I have installed latest version of nx monorepo (npx create-nx-workspace@latest). Currently latest version of nx is (14.3.6). After this I have added angular localization package (npm install @angular/localize). At this point now adding i18n attribute (<title i18n>Title</title>) works fine and the translation key is extracted into messages.xlf file.

The problem is if I try to use $localize inside a component in this case no error is reported but when I try to generate messages.xlf with ng extract-i18n test-app. An empty messages.xlf is generated.

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = $localize`my-app`;
}

messages.xlf

<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
  <file source-language="en-US" datatype="plaintext" original="ng2.template">
    <body>
    </body>
  </file>
</xliff>

So the question is there support for $localize inside NX Monorepo?
Maybe some configuration is missing in the project.json?

I am adding here a link to the github (https://github.com/hivaga/nx-localization-support) were current nx setup can be found.

PS I have tried latest vanilla angular application setup there $localize works as expected so obviously the problem is only on NX side!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷…雨湿花 2025-02-16 17:56:29

我找到了生成空的两个原因messages.xlf,而没有在同一时间报告任何错误:

  1. 缺少Application的polifills.js

      // polifills.js  
    导入'@angular/interize/init';
     
  2. 组件 *.ts中的错误导入中缺少导入量。文件。基本上$本地化应在导入语句中没有任何引用。这很奇怪,但这是它的工作方式。

      //必须删除此导入    
    从“@angular/interize/init”导入{$ entailize};
     

I have found the 2 reasons for the generation of empty messages.xlf without in the same time reporting any errors:

  1. Missing import statment in application's polifills.js

    // polifills.js  
    import '@angular/localize/init';
    
  2. Wrong import inside the component's *.ts. file. Basically $localize should be used without any reference to it inside the import statements. This is rather weird but it is how it works.

    // this import has to be removed    
    import {$localize} from "@angular/localize/init";
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文