PhpStorm Word Book插件使用

想要一个单词表,于是决定使用下wordBook(安装了Translation插件才会有)(虽然一点也不好用,没法更新单词、不能搜索等),但是仍然可以将就用一下

就用它的自动导入吧

用json文件导入

php脚本:

<?php

// Read contents from a.json file
$jsonString = file_get_contents('a.json');

// Decode JSON string to array
$dataArray = json_decode($jsonString, true);

// Initialize variables
$newArray = [];
$id = 0;

// Loop through each item in the array and transform as needed
foreach ($dataArray as $key => $value) {
    $newItem = [];
    $newItem['id'] = ++$id;

    // Convert camel case word to underscore-separated and add to new item
    $newItem['word'] = camelToUnderscore($key);
    $newItem['sourceLanguage'] = 'en';
    $newItem['targetLanguage'] = 'zh';
    $newItem['explanation'] = $value;
    $newItem['tags'] = [];
    $newItem['createdAt'] = 1682585254881;
    $newArray[] = $newItem;
}

// Encode the new array to JSON and write it to c.json file
file_put_contents('c.json', json_encode($newArray, JSON_UNESCAPED_UNICODE));

/**
 * Converts a camel case string to underscore separated string.
 *
 * @param string $camel The camel case string to convert.
 * @return string The underscore separated string.
 */
function camelToUnderscore(string $camel): string
{
    return strtolower(preg_replace('/(?<=[a-z])([A-Z])/', '_$1', $camel));
}

生成的导入文件长这样:

效果:

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值