-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set up json for tradional chinese and english. #100
Open
mariomui
wants to merge
1
commit into
pjeby:master
Choose a base branch
from
mariomui:feat/translate-to-zh-tw
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { moment } from 'obsidian'; | ||
import * as resources from './locales' | ||
|
||
type I18Config = ReturnType<typeof manuI18Config> | ||
export const i18next = (async function(global, factory) { | ||
|
||
const i18next = global.i18next | ||
if (i18next) { | ||
return await factory(i18next) | ||
} | ||
throw new Error("No instance of i18 found.") | ||
})( | ||
globalThis, | ||
async function factory(i18, config = manuI18Config()) { | ||
const current_lang = moment.locale(); | ||
const _config: I18Config = { | ||
...manuI18Config(), | ||
lng: current_lang, | ||
...config | ||
} | ||
// middleware | ||
await i18.init(_config) | ||
return i18; | ||
} | ||
); | ||
|
||
|
||
function manuI18Config(config = {}) { | ||
return ({ | ||
lng: 'en', | ||
debug: true, | ||
defaultNS: "translation", | ||
ns: "translation", | ||
resources, | ||
...config | ||
}) | ||
}; | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export const RENAME = "Rename"; | ||
export const CREATE_TAG_PAGE = "Create tag page"; | ||
export const CREATE_A_TAG = "Create A Tag"; | ||
export const OPEN_TAG_PAGE = "Open tag page"; | ||
export const NEW_SEARCH_FOR = "New search for"; | ||
export const REQUIRE = "Require"; | ||
export const IN_SEARCH = "in search"; | ||
export const EXCLUDE = "Exclude"; | ||
export const FROM_SEARCH = "from search"; | ||
export const enKeys = [ | ||
RENAME, | ||
CREATE_TAG_PAGE, | ||
CREATE_A_TAG, | ||
OPEN_TAG_PAGE, | ||
NEW_SEARCH_FOR, | ||
REQUIRE, | ||
IN_SEARCH, | ||
EXCLUDE, | ||
FROM_SEARCH | ||
] as const; | ||
|
||
const _en = enKeys.map((en_key) => ([en_key, en_key])) | ||
export default { | ||
translation: Object.fromEntries(_en) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
export {default as en} from "./en" | ||
export {default as zhTW} from "./zh-tw" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {enKeys, REQUIRE, IN_SEARCH, EXCLUDE, FROM_SEARCH, OPEN_TAG_PAGE} from "./en" | ||
type tKey = typeof enKeys[number] | ||
|
||
type PartialTranslation = Partial<Record<tKey,string>> | ||
type Namespace = "translation" | ||
|
||
const translation: PartialTranslation = { | ||
"Rename": "重命名", | ||
["Create A Tag"]: "创建標籤", | ||
["Create tag page"]: "创建標籤葉", | ||
["New search for"]: "重新搜索", | ||
[OPEN_TAG_PAGE]: "打開標簽葉", | ||
[REQUIRE]: "必须先包含", | ||
[IN_SEARCH]: "然后搜索", | ||
[EXCLUDE]: "排除", | ||
[FROM_SEARCH]: "在搜索之外", | ||
} | ||
|
||
|
||
|
||
type TranslationObject = { | ||
[K in Namespace]: PartialTranslation; | ||
}; | ||
|
||
const translationObject: TranslationObject = { | ||
translation, | ||
}; | ||
|
||
export default translationObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In short, this violates the very basics of translation.
One must NEVER concatenate strings for any reason.
Word order varies by language. Words need to conjugation to agree with substituted elements (gender agreement, case agreement (declination), sound-agreement (different words used depending if e/i or o/u are in the object, etc).
This fails for languages that:
#tag from-search exclude
exclude #tag":n" from-search
from-search exclude #tag
search #tag-target-from exclude
#tag-from-search #tag-target exclude
Etc.