locale: initial add-on

This commit is contained in:
thoradia 2017-04-15 16:36:25 +02:00
parent 3a202a3020
commit 1ab8c01495
7 changed files with 167 additions and 0 deletions

View File

@ -0,0 +1,2 @@
100:
- Initial add-on

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -0,0 +1,61 @@
################################################################################
# This file is part of LibreELEC - https://libreelec.tv
# Copyright (C) 2017-present Team LibreELEC
#
# LibreELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# LibreELEC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LibreELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
PKG_NAME="locale"
PKG_REV="100"
PKG_ARCH="any"
PKG_DEPENDS_TARGET="toolchain glibc"
PKG_SECTION="service"
PKG_SHORTDESC="Locale: allows users to set a custom locale to override the POSIX default"
PKG_LONGDESC="Locale ($PKG_REV) allows users to set a custom locale in the OS to override the POSIX default"
PKG_IS_ADDON="yes"
PKG_ADDON_NAME="Locale"
PKG_ADDON_TYPE="xbmc.service"
make_target() {
: # nothing to do
}
makeinstall_target() {
: # nothing to do
}
addon() {
mkdir -p "$ADDON_BUILD/$PKG_ADDON_ID/i18n"
cp -PR "$(get_build_dir glibc)/localedata/charmaps" \
"$(get_build_dir glibc)/localedata/locales" \
"$ADDON_BUILD/$PKG_ADDON_ID/i18n"
mkdir -p "$ADDON_BUILD/$PKG_ADDON_ID/locpath"
cp -PR $PKG_DIR/resources $ADDON_BUILD/$PKG_ADDON_ID
locales=""
for p in "$ADDON_BUILD/$PKG_ADDON_ID/i18n/locales"/*; do
l="$(basename $p)"
if [ "$l" = "POSIX" ]; then
continue
fi
locales="$locales|$l"
done
locales="${locales:1}"
sed -e "s/@LOCALES@/$locales/" \
-i $ADDON_BUILD/$PKG_ADDON_ID/resources/settings.xml
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings>
<category label="30000">
<setting label="30001" id="charmap" type="select" default="UTF-8" values="UTF-8" enable="false" />
<setting label="30002" id="locale" type="select" default="en_GB" values="@LOCALES@" />
</category>
</settings>

View File

@ -0,0 +1,74 @@
################################################################################
# This file is part of LibreELEC - https://libreelec.tv
# Copyright (C) 2017-present Team LibreELEC
#
# LibreELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# LibreELEC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LibreELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
import os
import subprocess
import xbmc
import xbmcaddon
import xbmcgui
class Monitor(xbmc.Monitor):
def __init__(self, *args, **kwargs):
xbmc.Monitor.__init__(self)
self.setLocale()
def onSettingsChanged(self):
self.setLocale()
def setLocale(self):
addon = xbmcaddon.Addon()
charmap = addon.getSetting('charmap')
locale = addon.getSetting('locale')
lang = locale + '.' + charmap
path = addon.getAddonInfo('path')
i18npath = os.path.join(path, 'i18n')
locpath = os.path.join(path, 'locpath')
localepath = os.path.join(locpath, lang)
profiled = os.path.join(path, 'profile.d')
profile = os.path.join(profiled, '10-locale.profile')
strings = addon.getLocalizedString
if os.path.isdir(locpath) == False:
os.makedirs(locpath)
if os.path.isdir(localepath) == False:
os.environ['I18NPATH'] = i18npath
subprocess.call(['localedef', '-f', charmap, '-i', locale, localepath])
if os.path.isdir(profiled) == False:
os.makedirs(profiled)
file = open(profile, 'w')
file.write('export LANG="' + lang + '"\n')
file.write('export LOCPATH="' + locpath + '"\n')
file.close()
current = os.environ.get('LANG', '')
if lang != current:
if xbmcgui.Dialog().yesno('Locale', strings(30003).format(current, lang)
) == True:
xbmc.restart()
if __name__ == '__main__':
Monitor().waitForAbort()

View File

@ -0,0 +1,19 @@
# Kodi Media Center language file
msgid ""
msgstr ""
msgctxt "#30000"
msgid "Configuration"
msgstr ""
msgctxt "#30001"
msgid "Charmap"
msgstr ""
msgctxt "#30002"
msgid "Locale"
msgstr ""
msgctxt "#30003"
msgid "Locale changed from {} to {}. Please reboot to apply globally."
msgstr ""

View File

@ -0,0 +1,4 @@
<settings>
<setting id="charmap" value="UTF-8" />
<setting id="locale" value="en_GB" />
</settings>