Skip to content

Commit

Permalink
Merge pull request #9 from shalldie/feature-i18n
Browse files Browse the repository at this point in the history
Feature i18n
  • Loading branch information
shalldie committed Jan 25, 2024
2 parents f766af0 + 0b1e368 commit d5acceb
Show file tree
Hide file tree
Showing 22 changed files with 387 additions and 64 deletions.
55 changes: 34 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<!-- 中英文切换 -->
<div align="right">

English | [中文](./README.zh-CN.md)

</div>
<!-- 中英文切换 end -->

<!-- 封面区域 -->
<div align="center">

<img src="https://user-images.githubusercontent.com/9987486/229472271-62a5d923-f7b7-416c-913e-c842ecc2de4d.png" width="320" />

### Note in terminal, based on github gist. 🧑‍💻
### Note in terminal, based on Github Gist. 🧑‍💻

`终端运行的记事本,基于 github gist 构建。`
`终端运行的记事本,基于 Github Gist 构建。`

[![Release Version](https://img.shields.io/github/v/release/shalldie/tnote?display_name=tag&logo=github&style=flat-square)](https://github.com/shalldie/tnote)
[![Docker Image Version](https://img.shields.io/docker/v/shalldie/tnote/latest?style=flat-square&logo=docker)](https://hub.docker.com/r/shalldie/tnote/tags)
Expand All @@ -14,44 +22,49 @@
[![Build Status](https://img.shields.io/github/actions/workflow/status/shalldie/tnote/ci.yml?logo=github&style=flat-square)](https://github.com/shalldie/tnote/actions)
[![License](https://img.shields.io/github/license/shalldie/tnote?logo=github&style=flat-square)](https://github.com/shalldie/tnote)

<img src="https://github.com/shalldie/tnote/assets/9987486/1964cbc5-3a10-47a1-9d13-66f8debb8ad0" width="900">
<img src="https://github.com/shalldie/tnote/assets/9987486/109dac72-1596-46d5-a727-e939f74a0fd2" width="900">

</div>

<!-- 封面区域 end -->

## 功能 🎯

- [x] 面板
- [x] 快捷键、鼠标操作
- [x] 存储持久化
- [x] Confirm、Prompt、Alert
- [x] 文件
- [x] 增删查改
- [x] 详情 📝
- [x] Markdown 高亮
- [x] 编辑、保存
- [x] 安装
`tnote` is a notepad application running on `Terminal`, allowing you to quickly access, synchronize content, and record your idea on different devices.

- [x] Application 🎯
- [x] Shortcut keys, mouse operations
- [x] Cloud storage persistence
- [x] i18n
- [x] Files
- [x] Add, delete, check, and modify
- [x] Detail 📝
- [x] Markdown highlighted
- [x] Edit and save
- [x] Installation
- [x] binary
- [x] go install
- [x] docker

## 准备&前提
## Prepare & Config

应用基于 github gist 构建,需要去 [申请 access token](https://github.com/settings/tokens/new),然后添加到环境变量 `TNOTE_GIST_TOKEN`
The application is built on GitHub Gist and requires [applying for an access token](https://github.com/settings/tokens/new), and then add it to the environment variable `TNOTE_GIST_TOKEN`

```bash
# ~/.bashrc
export TNOTE_GIST_TOKEN="<your_access_token>"
```

## 安装&运行
| Environment Variable | Default | Description |
| :-------------------- | :-----: | :---------------------------------------------------- |
| `TNOTE_GIST_TOKEN` | | `access token` applied for |
| `TNOTE_LANG` / `LANG` | `en_US` | Language preferred, optional values: `en_US``zh_CN` |

## Installation

### 1. binary

[Download](https://github.com/shalldie/tnote/releases),下载后直接执行即可,加入 `PATH` 更佳。
[Download](https://github.com/shalldie/tnote/releases), download and execute it, adding to `PATH` would be even better.

| 文件 | 适用系统 |
| File | OS |
| :------------------- | :----------------------- |
| `tnote.darwin-amd64` | `Mac amd64``Mac arm64` |
| `tnote.linux-amd64` | `Linux amd64` |
Expand All @@ -70,7 +83,7 @@ tnote

### 2. go install

需要 `go@1.20+` 环境
Need `go@1.20+` environment.

```bash
# install
Expand Down
103 changes: 103 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<!-- 中英文切换 -->
<div align="right">

[English](./README.md) | 中文

</div>
<!-- 中英文切换 end -->

<!-- 封面区域 -->
<div align="center">

<img src="https://user-images.githubusercontent.com/9987486/229472271-62a5d923-f7b7-416c-913e-c842ecc2de4d.png" width="320" />

### Note in terminal, based on Github Gist. 🧑‍💻

`终端运行的记事本,基于 Github Gist 构建。`

[![Release Version](https://img.shields.io/github/v/release/shalldie/tnote?display_name=tag&logo=github&style=flat-square)](https://github.com/shalldie/tnote)
[![Docker Image Version](https://img.shields.io/docker/v/shalldie/tnote/latest?style=flat-square&logo=docker)](https://hub.docker.com/r/shalldie/tnote/tags)
[![Go Version](https://img.shields.io/github/go-mod/go-version/shalldie/tnote?label=go&logo=go&style=flat-square)](https://github.com/shalldie/tnote)
[![Go Reference](https://pkg.go.dev/badge/github.com/shalldie/tnote.svg)](https://pkg.go.dev/github.com/shalldie/tnote)
[![Build Status](https://img.shields.io/github/actions/workflow/status/shalldie/tnote/ci.yml?logo=github&style=flat-square)](https://github.com/shalldie/tnote/actions)
[![License](https://img.shields.io/github/license/shalldie/tnote?logo=github&style=flat-square)](https://github.com/shalldie/tnote)

<img src="https://github.com/shalldie/tnote/assets/9987486/109dac72-1596-46d5-a727-e939f74a0fd2" width="900">

</div>

<!-- 封面区域 end -->

`tnote` 是一个运行在 `Terminal` 的记事本应用程序,让你可以在不同设备快速访问、同步内容,记录自己的想法。

- [x] 应用 🎯
- [x] 快捷键、鼠标操作
- [x] 云端存储持久化
- [x] 国际化
- [x] 文件
- [x] 增删查改
- [x] 详情 📝
- [x] Markdown 高亮
- [x] 编辑、保存
- [x] 安装
- [x] binary
- [x] go install
- [x] docker

## 准备&配置

应用基于 github gist 构建,需要去 [申请 access token](https://github.com/settings/tokens/new),然后添加到环境变量 `TNOTE_GIST_TOKEN`

```bash
# ~/.bashrc
export TNOTE_GIST_TOKEN="<your_access_token>"
```

| 环境变量 | 默认值 | 描述 |
| :-------------------- | :-----: | :----------------------------------- |
| `TNOTE_GIST_TOKEN` | | 申请到的 access token |
| `TNOTE_LANG` / `LANG` | `en_US` | 使用的语言,可选值:`en_US``zh_CN` |

## 安装&运行

### 1. binary

[Download](https://github.com/shalldie/tnote/releases),下载后直接执行即可,加入 `PATH` 更佳。

| 文件 | 适用系统 |
| :------------------- | :----------------------- |
| `tnote.darwin-amd64` | `Mac amd64``Mac arm64` |
| `tnote.linux-amd64` | `Linux amd64` |
| `tnote.linux-arm64` | `Linux arm64` |

example:

```bash
# install
wget -O tnote [url]
sudo chmod a+x tnote
sudo mv tnote /usr/local/bin/tnote
# run
tnote
```

### 2. go install

需要 `go@1.20+` 环境

```bash
# install
go install github.com/shalldie/tnote@latest
# run
tnote
```

### 3. docker

```bash
docker run -it -e TNOTE_GIST_TOKEN=$TNOTE_GIST_TOKEN shalldie/tnote:latest
```

## LICENSE

MIT
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ require (
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,5 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
7 changes: 4 additions & 3 deletions internal/app/file_list/del_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ import (

"github.com/shalldie/tnote/internal/app/pkgs/dialog"
"github.com/shalldie/tnote/internal/app/store"
"github.com/shalldie/tnote/internal/i18n"
)

func (m *FileListModel) delFile(filename string) {
store.Send(dialog.DialogPayload{
Mode: dialog.ModeConfirm,
Message: fmt.Sprintf("确定要删除文件「%v」吗?", filename),
Message: fmt.Sprintf(i18n.Get(i18nTpl, "del_confirm"), filename),
FnOK: func(args ...string) bool {
go func() {
go store.Send(store.StatusPayload{
Loading: true,
Message: "删除中...",
Message: i18n.Get(i18nTpl, "del_deleting"),
})

store.Gist.UpdateFile(filename, nil)

store.Send(store.StatusPayload{
Loading: false,
Message: fmt.Sprintf("「%v」完成删除", filename),
Message: fmt.Sprintf(i18n.Get(i18nTpl, "del_done"), filename),
Duration: 5,
})
store.Send(store.CMD_REFRESH_FILES(""))
Expand Down
5 changes: 3 additions & 2 deletions internal/app/file_list/file_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/shalldie/tnote/internal/app/pkgs/model"
"github.com/shalldie/tnote/internal/app/store"
"github.com/shalldie/tnote/internal/gist"
"github.com/shalldie/tnote/internal/i18n"
"github.com/shalldie/tnote/internal/utils"
)

Expand Down Expand Up @@ -177,7 +178,7 @@ func (m FileListModel) headerView() string {
borderStyle := listBorderStyle.GetBorderStyle()

titleStyle := lipgloss.NewStyle().Foreground(astyles.PRIMARY_ACTIVE_COLOR).Padding(0, 1).Bold(m.Active)
title := titleStyle.Render("文件列表")
title := titleStyle.Render(i18n.Get(i18nTpl, "filelist_title"))
// title := titleStyle.Render("Mr. Pager")
// ━┓
line := lipgloss.NewStyle().Foreground(m.curForeground()).Render(strings.Repeat(borderStyle.Top, utils.MathMax(0, m.Width-lipgloss.Width(title)+1)) + borderStyle.TopRight)
Expand Down Expand Up @@ -255,7 +256,7 @@ func New() FileListModel {
list.DisableQuitKeybindings()
list.KeyMap = newListKeyMap()
list.AdditionalFullHelpKeys = additionalKeyMap
list.FilterInput.Prompt = "过滤:"
list.FilterInput.Prompt = i18n.Get(i18nTpl, "filelist_filter")

// model
model := FileListModel{
Expand Down
85 changes: 85 additions & 0 deletions internal/app/file_list/i18n_tpl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package file_list

var i18nTpl = `
# del file
del_confirm:
en_US: Are you sure you want to delete the file 「%v」?
zh_CN: 确定要删除文件「%v」吗?
del_deleting:
en_US: deleting...
zh_CN: 删除中...
del_done:
en_US: 「%v」Complete deletion
zh_CN: 「%v」完成删除
# new file
new_namevalid:
en_US: The file name length needs to be greater than 3
zh_CN: 文件名长度需要大于3
new_message:
en_US: New file, please enter the file name
zh_CN: 新建文件,请输入文件名
new_creating:
en_US: creating...
zh_CN: 新建中...
new_done:
en_US: 「%v」Complete new creation
zh_CN: 「%v」完成新建
# rename file
rename_message:
en_US: Rename file「%v」
zh_CN: 重命名文件「%v」
rename_renaming:
en_US: renaming...
zh_CN: 重命名中...
rename_done:
en_US: 「%v」->「%v」Complete renaming
zh_CN: 「%v」->「%v」完成重命名
# file list
filelist_title:
en_US: File List
zh_CN: 文件列表
filelist_filter:
en_US: "Filter:"
zh_CN: 过滤:
# keys
key_up:
en_US: up
zh_CN: 上
key_down:
en_US: down
zh_CN: 下
key_pgup:
en_US: prev pg
zh_CN: 上一页
key_pgdown:
en_US: next pg
zh_CN: 下一页
key_filter:
en_US: filter
zh_CN: 过滤
key_cancel:
en_US: cancel
zh_CN: 取消
key_filter_apply:
en_US: apply filter
zh_CN: 应用过滤
key_filter_more:
en_US: more
zh_CN: 更多
key_filter_less:
en_US: less
zh_CN: 折叠
# key custom
key_new:
en_US: new
zh_CN: 新建
key_rename:
en_US: rename
zh_CN: 重命名
key_edit:
en_US: edit
zh_CN: 编辑
key_del:
en_US: delete
zh_CN: 删除
`

0 comments on commit d5acceb

Please sign in to comment.