www.91084.com

GVKun编程网logo

得到通知是 wordpress “WP_Scripts::localize 被错误地调用”

5

在本文中,我们将给您介绍关于得到通知是wordpress“WP_Scripts::localize被错误地调用”的详细内容,此外,我们还将为您提供关于Angular$localize不是一个函数、An

在本文中,我们将给您介绍关于得到通知是 wordpress “WP_Scripts::localize 被错误地调用”的详细内容,此外,我们还将为您提供关于Angular $localize 不是一个函数、Angular 库,找不到名称 $localize、Autolink 不适用于 react-native 0.63.4 和 react-native-localize、Flex 国际化(flex Localize)的知识。

本文目录一览:

得到通知是 wordpress “WP_Scripts::localize 被错误地调用”

得到通知是 wordpress “WP_Scripts::localize 被错误地调用”

如何解决得到通知是 wordpress “WP_Scripts::localize 被错误地调用”

完整消息: 注意: WP_Scripts::localize 被错误地调用。 $l10n 参数必须是一个数组。要将任意数据传递给脚本,请改用 wp_add_inline_script() 函数。有关更多信息,请参阅在 wordpress 中调试。 (此消息是在 5.7.0 版中添加的。)在 /home3/dduconne/public_html/wp-includes/functions.PHP 上的第 5313 行

wordpress 更新到 5.7.0 后出现

解决方法

好的,因为有很多观点,而之前的答案只是把它放在地毯下。

是的,现在是警告,但谁知道会发生什么,这是有原因的警告,禁用某些东西并不能解决它,开发人员暂时将其设置为警告是有原因的。

当我们等待插件开发者解决问题时,您可以通过在 php.ini 中启用 php_xdebug 来找出问题的根源。我建议在调试后不要离开它,因为我不确定启用它的性能成本。

php_xdebug 将返回所有受影响文件的堆栈,您可以从那里追踪到问题的根源。一旦找到来源,修复就很容易了。罪魁祸首很可能是 wp_localize_script(),它要求最后一个参数是 array()

所以你会发现这样的东西:

  1. wp_localize_script( ''handle'',''object_name'',''l10n_culprit_string'' );

应该变成:

  1. wp_localize_script( ''handle'',array( ''l10n_culprit_string'' ) );

问题的解决方案来自here

,

这是 Wordpress 5.7 中出现的新警告。如果您不想看到它,但仍希望将 WP_DEBUG 设置为 true,则可以通过在主题的 functions.php 中添加以下示例来禁用该消息:

  1. add_filter(''doing_it_wrong_trigger_error'',function () {return false;},10,0);
,

如果您使用的是 wp5.7 和 php7.4,现在是一个通知,但更改为 php8 可能会报告错误。对我来说,当我(在我自己的代码中)将传递的值更改为数组时(是的,可能涉及的 js 中也需要进行一些更改),一切正常。

Angular $localize 不是一个函数

Angular $localize 不是一个函数

如何解决Angular $localize 不是一个函数

在我的 ts 文件中尝试使用 $localize 时遇到一个奇怪的错误。我收到此错误

  1. Error: Uncaught (in promise): TypeError: _angular_localize_init__WEBPACK_IMPORTED_MODULE_3__.$localize is not a function
  2. TypeError: _angular_localize_init__WEBPACK_IMPORTED_MODULE_3__.$localize is not a function

我在模板文件中进行了本地化,并且调用 ng build 没有错误。当调用包含 $localize 方法的组件时,错误发生在运行时。我的 ts 代码是

  1. private handleServerErrors(error: HttpErrorResponse): void {
  2. // Handle errors
  3. this.complete = true;
  4. switch (error.status) {
  5. ...
  6. case 500:
  7. default:
  8. // Could not update user
  9. this.errorMessage = $localize`:@@CalmBreathing_Desc_Short:Cobblers`;
  10. break;
  11. }
  12. console.error(error);
  13. }

polyfills.ts 文件在顶部有这个

  1. /***************************************************************************************************
  2. * Load `$localize` onto the global scope - used if i18n tags appear in Angular templates.
  3. */
  4. import ''@angular/localize/init'';

这是带有 nodejs 12 的 Angular 11.2.8。有什么想法吗?

解决方法

所以这是 WebStorm 试图提供帮助。它已将以下行添加到我的 ts 文件的顶部

  1. import { $localize } from ''@angular/localize/init'';

导致它不起作用

Angular 库,找不到名称 $localize

Angular 库,找不到名称 $localize

如何解决Angular 库,找不到名称 $localize

我正在使用 Nx 工具将我的 Angular 11 应用程序重构为库。我的主应用程序在 @angular/localize 中有 @angular/localize 作为依赖项和 polyfills.ts 导入。在我的库代码中每次使用 $localize 都会生成 Typescript 错误 TS2304: Cannot find name ''$localize''。我的图书馆没有自己的 package.json 文件。应用程序构建没有错误。看起来像是 Typescript 打字问题。有什么想法吗?

库 tsconfig.lib.json

  1. {
  2. "extends": "./tsconfig.json","compilerOptions": {
  3. "outDir": "../../../dist/out-tsc","target": "es2015","declaration": true,"declarationMap": true,"inlinesources": true,"types": [],"lib": [
  4. "dom","es2018"
  5. ]
  6. },"angularCompilerOptions": {
  7. "skipTemplateCodegen": true,"strictMetadataEmit": true,"enableResourceInlining": true
  8. },"exclude": [
  9. "src/test.ts","**/*.spec.ts"
  10. ],"include": [
  11. "**/*.ts"
  12. ]
  13. }

库中的 tsconfig.json

  1. {
  2. "extends": "../../../tsconfig.base.json","files": [],"include": [],"references": [
  3. {
  4. "path": "./tsconfig.lib.json"
  5. },{
  6. "path": "./tsconfig.spec.json"
  7. }
  8. ]
  9. }

角度版本

  1. Angular CLI: 11.1.1
  2. Node: 14.15.4
  3. OS: win32 x64
  4. Angular: 11.1.0
  5. ... animations,cdk,common,compiler,compiler-cli,core
  6. ... elements,forms,language-service,localize,material
  7. ... platform-browser,platform-browser-dynamic,router
  8. Ivy Workspace: <error>
  9. Package Version
  10. ---------------------------------------------------------
  11. @angular-devkit/architect 0.1002.1
  12. @angular-devkit/build-angular 0.1101.1
  13. @angular-devkit/core 10.2.1
  14. @angular-devkit/schematics 11.0.7
  15. @angular/cli 11.1.1
  16. @schematics/angular 11.0.7
  17. @schematics/update 0.1101.1
  18. rxjs 6.6.3
  19. typescript 4.1.3

解决方法

@angular/localize/init 的导入可能会导致 no-import-side-effect 的 tslint 错误,因为它添加到全局上下文中(即副作用)。要修复此错误,请将以下内容添加到您的 tslint.config

“无导入副作用”:[ 真的, { "ignore-module": "(core-js/.|zone\\.js/.|@angular/localize/init)$" } ]

,

我遇到了同样的问题,我在 polyfills.ts 的第一行添加了以下代码解决了我的问题。

  1. import ''@angular/localize/init'';

Autolink 不适用于 react-native 0.63.4 和 react-native-localize

尝试通过 npx react-native run-android 命令再次运行项目。

如果您使用的是 iOS 设备,则:

cd ios && pod install npx react-native run-ios 如果仍然无效,请尝试再次安装 npm 包并按照文档进行操作。

,

使用

npx react-native link react-native-localize

代替

react-native link react-native-localize

希望能帮到你

Flex 国际化(flex Localize)

Flex 国际化(flex Localize)

项目中用到flex国际化,虽然以前也用过,也是直接嵌入到程序中,现在有要求要放到外面模块中去,虽然网上教程多多,但是遇到还是遇到很多问题,籍此写下此文,加深印象之用。如果有哪位仁兄只好也用到此,希望能有所帮助,废话至此,正文开始。

先说说编译到主程序中去的方法吧。

1.创建资源文件夹

譬如可以在src文件夹下创建Locale文件夹,然后在此文件夹再次创建每个地区的资源文件夹,譬如de_DE,zh_CN.

然后分别创建后缀名为.properties的资源文件,分别放到各个地区的文件夹中。资源文件是可以包括任何事情,从字符串,数字,格式化和图片到样式。每个地区可以生成一个单独的文件。参考:CreateLocaleFiles.png

2.创建资源文件

创建了名为resources.properties的资源文件,内容为:

 

## resources.properties file for locale de_DE ## 

# contact-form labels and assets 
contact.title=Contact Form 
contact.flagImg=assets/us.gif 
contact.submit=Submit 

# contact-form fields 
contact.field.name=Name 
contact.field.streetAddress=Street Address 
contact.field.city=City 
contact.field.state=State 
contact.field.zipCode=ZIP Code 
contact.field.country=Country

 

3.创建mxml文件

 

<?xml version="1.0" encoding="utf-8"?>
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009" 
		  xmlns:s="library://ns.adobe.com/flex/spark" 
		  xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%">
	<fx:Metadata>
		[ResourceBundle("resources")]
	</fx:Metadata>
	<fx:Script>
		<![CDATA[
			private var locales:Array = [{label:"English (United States)",locale:"en_US"},{label:"中文 (中国)",locale:"zh_CN"},{label:"German (Denmark)",locale:"de_DE"},{label:"french (France)",locale:"fr_FR"},{label:"Japanese (Japan)",locale:"ja_JP"}];
			
			private function comboChangeHandler():void
			{
				resourceManager.localeChain = [localeComboBox.selectedItem.locale];
			}
		]]>
	</fx:Script>
	
	<s:Panel title="{resourceManager.getString('resources','contact.title')}" color="black" borderAlpha="0.15" width="350">
		<s:layout>
			<s:VerticalLayout horizontalAlign="center" paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10" />
		</s:layout>
		
		<mx:Form width="100%" color="0x323232">
			<mx:FormItem label="{resourceManager.getString('resources','contact.field.name')}">
				<s:TextInput />
			</mx:FormItem>
			<mx:FormItem label="{resourceManager.getString('resources','contact.field.streetAddress')}">
				<s:TextInput />
			</mx:FormItem>
			<mx:FormItem label="{resourceManager.getString('resources','contact.field.city')}">
				<s:TextInput />
			</mx:FormItem>
			<mx:FormItem label="{resourceManager.getString('resources','contact.field.state')}">
				<s:TextInput />
			</mx:FormItem>
			<mx:FormItem label="{resourceManager.getString('resources','contact.field.zipCode')}">
				<s:TextInput />
			</mx:FormItem>
			<mx:FormItem label="{resourceManager.getString('resources','contact.field.country')}">
				<s:TextInput />
			</mx:FormItem>
			<mx:FormItem>
				<s:Button label="{resourceManager.getString('resources','contact.submit')}" />
			</mx:FormItem>
		</mx:Form>
	</s:Panel>
	<mx:Spacer height="15" />
	
	<s:HGroup width="350" verticalAlign="middle">
		<mx:Spacer width="100%" />
		<mx:Image source="{resourceManager.getString('resources','contact.flagImg')}"/>
		<mx:ComboBox id="localeComboBox" dataProvider="{locales}" change="comboChangeHandler()"/>
	</s:HGroup>
</s:VGroup>

 

 4.配置Flex 编译参数

选中项目名称右键-Properties-Flex Complier-Addtional compiler arguments中添加

 

-locale=en_US,zh_CN -allow-source-path-overlap=true -source-path=Locale/{locale}

 这样就可以了,你可以通过切换发现可以实现国际化了,哈哈,不过只有两种地区的简单demo。

 

再谈谈用module分别加载不同地区资源

 

到底怎样加载这些资源文件决定于你的程序许多支持多少地区本地化。

a.如果你仅仅只是支持一到两个地区的本地化,那么一般来说就是直接编译到程序中。

b.如果要支持很多种本地化,一般选择在运行时加载所需的本地化资源。资源模块和编译入主程序相比,资源模块是一种比较好的本地化方式,因为它指定的资源模块可以在运行时加载。这样可以减小主程序的文件大小,但是如你所见你必须为每个资源模块加载一个单独的swf文件。这样的话会增加网络请求并且合成的主程序的大小比直接编译入主程序的方式更大。尽管如此,如果你有很多本地化的需求,分别单独的加载它们从长远来看会节省资源。

1.2 和上面一样

3.建立mxml文件

 

<?xml version="1.0" encoding="utf-8"?>
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009" 
		  xmlns:s="library://ns.adobe.com/flex/spark" 
		  xmlns:mx="library://ns.adobe.com/flex/mx" 
		  width="100%" 
		  height="100%" 
		  creationComplete="initApp()">
	<fx:Script>
		<![CDATA[
		import mx.controls.Alert;
		import mx.events.ResourceEvent;
		import mx.resources.ResourceBundle;
		
		[Bindable]
		private var locales:Array = [ "zh_CN","de_DE" ];
		
		private function initApp():void {
			/* Set the index to -1 so that the prompt appears 
			when the application first loads. */
			localeComboBox.selectedindex = -1;            
		}
		
		private function registrationComplete():void {
			Alert.show(resourceManager.getString('resources','thanks'));
		}  
		
		private function comboChangeHandler():void {
			var newLocale:String = String(localeComboBox.selectedItem);
			
			/* Ensure that you are not loading the same resource module more than once. */
			if (resourceManager.getLocales().indexOf(newLocale) != -1) {
				completeHandler(null);
			} else {
				// Build the file name of the resource module.
				var resourceModuleURL:String = newLocale + "_ResourceModule.swf";
				
				var eventdispatcher:IEventdispatcher = 
					resourceManager.loadResourceModule(resourceModuleURL);
				eventdispatcher.addEventListener(ResourceEvent.COMPLETE,completeHandler);
			}            
		}
		
		private function completeHandler(event:ResourceEvent):void {
			resourceManager.localeChain = [ localeComboBox.selectedItem ];
			
			/* This style is not bound to the resource bundle,so it must be reset when 
			the new locale is selected. */
			var test:String = resourceManager.getString('resources','contact.field.city');
			b1.setStyle("downSkin",resourceManager.getClass("RegistrationForm","flag"));            
		}        
	]]></fx:Script>
	<s:Image source="{resourceManager.getClass('resources','flag')}"/>
	<mx:ComboBox id="localeComboBox" 
				 prompt="Select One..."
				 dataProvider="{locales}"
				 change="comboChangeHandler()"/>
	<mx:Form width="100%" color="0x323232">
		<mx:FormItem label="{resourceManager.getString('resources','contact.field.name')}">
			<s:TextInput />
		</mx:FormItem>
		<mx:FormItem label="{resourceManager.getString('resources','contact.field.streetAddress')}">
			<s:TextInput />
		</mx:FormItem>
		<mx:FormItem label="{resourceManager.getString('resources','contact.field.city')}">
			<s:TextInput />
		</mx:FormItem>
		<mx:FormItem label="{resourceManager.getString('resources','contact.field.state')}">
			<s:TextInput />
		</mx:FormItem>
		<mx:FormItem label="{resourceManager.getString('resources','contact.field.zipCode')}">
			<s:TextInput />
		</mx:FormItem>
		<!--<mx:FormItem label="@Resource(key='contact.field.zipCode',bundle='resources')">
			<s:TextInput />
		</mx:FormItem>-->
		<mx:FormItem>
			<s:Button label="{resourceManager.getString('resources','contact.submit')}" />
		</mx:FormItem>
	</mx:Form>
	
	<s:Button id="b1" 
			  label="{resourceManager.getString('resources','submit_button')}" 
			  click="registrationComplete()"/>
</s:VGroup>
 

4.确定需要哪些资源束

在你编译资源模块之前,你必须知道那些资源束应该放到它里面。换句话说,你必须要知道那些资源是你的主程序-包括它的框架-真正需要的。这不仅仅包括你所创建程序需要的的资源,而且也包括程序框架需要的资源

在你的flex bulider中找到mxmlc.exe 文件,例如我的在:C:\Program Files\Adobe\Adobe Flash Builder 4.6\sdks\4.6.0\bin,执行

 

mxmlc -locale= -resource-bundle-list=myresources.txt F:\demo\Demo\src\view\resource\ResourceMoudleDemo.mxml

 

当你使用resource-bundle-list选项时,你还必须设置locale的值为空。

myresource.txt 就是待会要把你所有要国际化的页面和框架所需的所有文件名输出到这个文件中,地址就在mxmlc.exe文件的同一目录

F:\demo\Demo\src\view\resource\ResourceMoudleDemo.mxml 就是你要国际化的页面的绝对路径

执行完后到myresource.txt中查看,内容为:

 

bundles = collections components containers controls core effects layout resources skins styles textLayout 

 其中的resources就是自定义的资源文件,其他就是框架所用的文件了

5.把所有的文件都编译到一个swf中

 

mxmlc -locale=de_DE
-source-path=F:\demo\Demo\src\Locale\{locale} -include-resource-bundles=resources,collections,components,containers,controls,core,effects,layout,skins,styles,textLayout -output de_DE_ResourceModule.swf

 这个时候就会在mxmlc.exe中相同的目录中生成de_DE_ResourceModule.swf。

然后你再改变下-locale=zh_CN,生成zh_CN_ResourceModule.swf。

然后把这两个swf放到主程序相同目录下,测试加载即可。

今天关于得到通知是 wordpress “WP_Scripts::localize 被错误地调用”的介绍到此结束,谢谢您的阅读,有关Angular $localize 不是一个函数、Angular 库,找不到名称 $localize、Autolink 不适用于 react-native 0.63.4 和 react-native-localize、Flex 国际化(flex Localize)等更多相关知识的信息可以在本站进行查询。

本文标签: