VS code - code Snippet

For anyone working on the UI and using VS Code, you can create a user Snippet and keyboard shortcut so that you can easily add the localization code when needed. Add the user Snippet to VS Code by going to File->Preferences->User Snippets and pasting the code below in the javascript.json file.
    "AddLocalizedString": {

        "prefix": "loc",

        "body": [

            "{this.props.translate('${1:stringKey}')}$0"

        ],

        "description": "Add placeholder for localized string. Replace stringKey with localized string key."

    } 

To use your snippet you would type loc to insert this line in your code:    {this.props.translate('stringKey')}  

then replace the stringKey text with the key of the localized string found in the en.js language file. 

For example: 

{this.props.translate('stringKey')} for the string 'Schedule' becomes {this.props.translate('scheduleString')} 

You can also add a keyboard shortcut by going to File->Preferences->Keyboard Shortcuts and then clicking the link at the top to keybindings.json. Add the following to the keybindings.json file: 

  {

    "key": "ctrl+l ctrl+l",

    "command": "editor.action.insertSnippet",

    "when": "editorTextFocus",

    "args": {

      "langId": "javascript",

      "name": "AddLocalizedString"

    }

  } 

When you enter ctrl+l twice, the code for localizing a string will be inserted. You can change the "key" in the shortcut above to whatever combination works for you.

 

转载于:https://www.cnblogs.com/cw_volcano/p/10701747.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值