Title: [i18n] support i18n-localiza in template expression. · Issue #48229 · angular/angular · GitHub
Open Graph Title: [i18n] support i18n-localiza in template expression. · Issue #48229 · angular/angular
X Title: [i18n] support i18n-localiza in template expression. · Issue #48229 · angular/angular
Description: Which @angular/* package(s) are relevant/related to the feature request? compiler, localize Description example: {{ nikename ?? 'ano' }} for now to support i18n, I should rewrite those code: {{ nickname ?? $$ANO }} ...
Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? compiler, localize Description example: {{ nikename ?? 'ano' }} for now to support i18n, I should rewrite tho...
X Description: Which @angular/* package(s) are relevant/related to the feature request? compiler, localize Description example: <span> {{ nikename ?? 'ano' }} </span> for now to support i18n, ...
Opengraph URL: https://github.com/angular/angular/issues/48229
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[i18n] support i18n-localiza in template expression.","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\r\n\r\ncompiler, localize\r\n\r\n### Description\r\n\r\nexample:\r\n```angular\r\n\u003cspan\u003e {{ nikename ?? 'ano' }} \u003c/span\u003e\r\n```\r\n\r\nfor now to support i18n, I should rewrite those code:\r\n```angular\r\n\u003cspan\u003e {{ nickname ?? $$ANO }} \u003c/span\u003e\r\n```\r\n```ts\r\nclass MyComponent {\r\n readonly $$ANO = $localiza`:@@ANO:ano`;\r\n}\r\n```\r\n\r\nor like:\r\n```angular\r\n\u003cspan\u003e\r\n \u003cng-container *ngIf=\"nickname;else Str\"\u003e{{nickname}}\u003c/ng-container\u003e\r\n \u003cng-template #Str\u003e\u003cng-container i18n=\"@@ANO\"\u003eano\u003c/ng-container\u003e\u003c/ng-template\u003e\r\n\u003cspan\u003e\r\n```\r\n\r\n### Proposed solution\r\n\r\n\r\n```angular\r\n\u003cspan\u003e {{ nikename ?? $localiza(':@@ANO:ano') }} \u003c/span\u003e\r\n```\r\n\r\n\u003e after read the source code. I think inject an function for template is better choose then pipe.\r\n\r\nthose code will compile to on [consts]():\r\n\r\n```ts\r\n$localiza.trans[\":@@ANO:ano\"] = $localiza`:@@ANO:ano`\r\n```\r\n#### Tips\r\n1. `$localize` only support string literal.\r\n \u003e eg: `$localize(str_var)` is no support, suppose use variable, why not `` str_var = $localize`text` ``\r\n2. `$localize` only support one argument.\r\n \u003e suppose transform code:\r\n \u003e\r\n \u003e ```ts\r\n \u003e $localize(':@@MY_INTRO:my name is ', username, ', I\\'m ', age ,' years old.')\r\n \u003e ```\r\n \u003e\r\n \u003e to\r\n \u003e\r\n \u003e ```ts\r\n \u003e $localize`:@@MY_INTRO:my name is \\${name}, I'm ${age} years old.`;\r\n \u003e ```\r\n \u003e\r\n \u003e consider using `html` would get better readability and maintainability:\r\n \u003e\r\n \u003e ```html\r\n \u003e \u003cng-container i18n=\"@@MY_INTRO\"\u003e\r\n \u003e my name is {{name}}, I'm {{age}} years old.\r\n \u003e \u003c/ng-container\u003e\r\n \u003e ```\r\n\r\n### Alternatives considered\r\n\r\n_noop_\r\n\r\n\u003e For now. I'm trying to make those code work in my project by hacking the source code. I hope someone could give me better suggest.\r\n\r\n### Relational link\r\n\r\n- https://github.com/angular/angular/pull/39122\r\n- https://github.com/angular/angular/issues/35563#issuecomment-840027460","author":{"url":"https://github.com/Gaubee","@type":"Person","name":"Gaubee"},"datePublished":"2022-11-25T02:01:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/48229/angular/issues/48229"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:51b5ff11-5fa2-7274-d402-46c895ead47d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D092:2A07B7:3A8B128:4C324B5:6974C7FC |
| html-safe-nonce | 0565c0aeac2152b5117739a259935970799883305ec4143b7b30a9102d50dc5c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDkyOjJBMDdCNzozQThCMTI4OjRDMzI0QjU6Njk3NEM3RkMiLCJ2aXNpdG9yX2lkIjoiNzUyNTE0ODk0NDgxMjUyNTU2NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 014655023b44cdf4b7862e0ee690a0f234e2135882f953cd17f1fb3f41e40eda |
| hovercard-subject-tag | issue:1463948142 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/48229/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f74c0a0f5d6cd4111c30100c992b7ae9727a863d4ace6b43f15f59374604578d/angular/angular/issues/48229 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f74c0a0f5d6cd4111c30100c992b7ae9727a863d4ace6b43f15f59374604578d/angular/angular/issues/48229 |
| og:image:alt | Which @angular/* package(s) are relevant/related to the feature request? compiler, localize Description example: {{ nikename ?? 'ano' }} for now to support i18n, I should rewrite tho... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Gaubee |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4a4bf5f4e28041a9d2e5c107d7d20b78b4294ba261cab243b28167c16a623a1f |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 488b30e96dfd057fbbe44c6665ccbc030b729dde |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width