Skip to content
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

Add localization #22

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ This script will automatically do the following:
GitHub actions is configured to build the package afterwards and draft a release.

# 💬 Todo:
- [ ] Localization
- [x] Localization
- [ ] Search Command
- [ ] Emoticon Creator
- [ ] Chrome OS Support
Expand Down
25 changes: 21 additions & 4 deletions limoji
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ printTick() {

# A function that prints the selected emoticon to the console
printEmoticon() {
printTick "${1} was copied to the clipboard successfully:"
printTick "${1} $MSG_COPIED_TO_CLIPBOARD"
printf -- '%b' "${!1}" | tee >(copyToClipboard)
printf -- '%s\n' ""
}
Expand Down Expand Up @@ -67,15 +67,15 @@ printCmdVersion() {

# Compare current version against the one fetched from the API
if [[ "$limoji_version" < "$latest_version" ]]; then
printf -- ' (\e[1;93mUpdate available\e[0m)\n\n'
printf -- ' (\e[1;93m'"$MSG_UPDATE_AVAILABLE"'\e[0m)\n\n'
printInfo "Limoji $latest_version is available."

# Check if Limoji's parent directory is a git repository
if [[ $is_git ]]; then
printf -- ' %s\n' "Run 'git pull' to update."
fi
else
printf -- ' (\e[1;32mUp to date\e[0m)\n'
printf -- ' (\e[1;32m'"$MSG_UP_TO_DATE"'\e[0m)\n'
fi
else
printf -- '\n'
Expand All @@ -91,6 +91,17 @@ fetchLatestRelease() {
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}

# Select and load the appropriate language
selectLanguage() {
# If language is undefined in limoji.conf, select one automatically, based on system preference
if [[ ! -n "${language}" ]]; then
language=$(echo $LANG | cut -d_ -f1)
fi

# Load the appropriate file
source "${config_path}"/translations/"${language}"
}

# Function that picks a random emoticon name
fetchRandomName() {
# Generate a random number between 1 and unicode line count
Expand Down Expand Up @@ -195,6 +206,12 @@ main() {
# First, if no args are given, give the invalid argument message and exit
(( ${#} == 0 )) && { invalidArgument; exit 1; }

# Load the config file
source "${config_path}"/limoji.conf

# Setup language & load translations
selectLanguage

# Next, try to get a clipboard working
setupClipboard

Expand All @@ -219,7 +236,7 @@ main() {
if [[ -n "${!1}" ]]; then
printEmoticon "${1}"
else
printCross "The specified emoji doesn't exist!"
printCross "$MSG_INVALID_EMOTICON"
printf -- '%s\n' "Try 'limoji --emoticons' for a list of available emojis."
fi
;;
Expand Down
2 changes: 2 additions & 0 deletions limoji.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Uncomment to override language setting
#language=en_US
5 changes: 5 additions & 0 deletions translations/el_GR
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MSG_COPIED_TO_CLIPBOARD='αντιγράφηκε στο πρόχειρο με επιτυχία:'
MSG_UP_TO_DATE='Ενημερωμένο'
MSG_UPDATE_AVAILABLE='Διαθέσιμη ενημέρωση'
MSG_VERSION_IS_AVAILABLE='Το Limoji''είναι διαθέσιμο.'
MSG_INVALID_EMOTICON='Το συγκεκριμένο emoji δεν υπάρχει!'
5 changes: 5 additions & 0 deletions translations/en_US
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MSG_COPIED_TO_CLIPBOARD='was copied to the clipboard successfully:'
MSG_UP_TO_DATE='Up to date'
MSG_UPDATE_AVAILABLE='Update available'
MSG_VERSION_IS_AVAILABLE='Limoji '"$latest_version"' is available.'
MSG_INVALID_EMOTICON=$'The specified emoji doesn\'t exist!'
5 changes: 5 additions & 0 deletions translations/ja_JP
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MSG_COPIED_TO_CLIPBOARD='がクリップボードに正常にコピーされました:'
MSG_UP_TO_DATE='最新の'
MSG_UPDATE_AVAILABLE='利用可能なアップデート'
MSG_VERSION_IS_AVAILABLE='Limoji '"$latest_version"' 利用可能です.'
MSG_INVALID_EMOTICON=$'指定された絵文字は存在しません!'