如何在Android Studio中找到所有相关的硬编码字符串? [英] How can I find all RELEVANT hard coded strings in Android Studio?

查看:415
本文介绍了如何在Android Studio中找到所有相关的硬编码字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前曾有人问过这个问题,但我不明白这些问题的答案在大型项目中是否令人满意.

A few flavors of this question have been asked before, but I don't understand how the answers to them are satisfactory for large projects.

我的目标是在应用程序中找到需要本地化的任何硬编码字符串,因此我执行以下操作:

My goal here is to find any hardcoded strings in my application that need to be localized, so I do the following:

  1. 从项目层次结构中选择我要运行硬编码字符串检查的目录
  2. 导航到分析->按名称运行检查...
  3. 选择硬编码字符串"
  4. 选中目录"单选按钮后,单击确定"以运行检查

这时,我得到大约3500个匹配,其中2500个是记录语句.我运行sed命令从项目中删除所有日志记录,然后重复上述步骤.剩下1000次点击.在这700亿个字符串中,有分配给常量的字符串文字,因此我要执行以下操作:

At this point, I get about 3500 hits, 2500 of which are logging statements. I run a sed command to remove all logging from my project and repeat the steps above. This leaves 1000 hits. Of those about 700 hundred are strings literals assigned to constants, so I do the following:

  1. 导航到Android Studio->首选项
  2. 导航到检查->国际化问题->硬编码字符串
  3. 在右边的框中,选中忽略分配给常量的文字"

我重新运行了支票并最终获得300次点击.在大约200种中,有某种形式的用于读写JSON属性的硬编码标签,而99种是为文件名和共享首选项之类的内容构建的字符串.

I rerun the check and end up with 300 hits. Of those about 200 are some form of hardcoded tag for reading/writing JSON properties, and 99 are built strings for things like file names and shared preferences.

这个2个小时的过程给我留下了1个未本地化的实际字符串文字.

This 2 hour process left me with 1 actual string literal that wasn't being localized.

问题:是否有一种内置的方式说:运行此本地化检查,但忽略匹配此[[]]正则表达式列表的行"?

The question: Is there a built-in way to say, "run this localization check, but ignore lines that match this [list of] regular expression[s]"?

推荐答案

只需在日志行后添加//NON-NLS 即可取消警告.

Just add //NON-NLS after your log line to suppress the warning.

NGMCLogger.i(TAG, "This log does not need translation"); //NON-NLS

这篇关于如何在Android Studio中找到所有相关的硬编码字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆