diff --git a/packages/addons/service/locale/changelog.txt b/packages/addons/service/locale/changelog.txt new file mode 100644 index 0000000000..537a90c254 --- /dev/null +++ b/packages/addons/service/locale/changelog.txt @@ -0,0 +1,2 @@ +100: +- Initial add-on diff --git a/packages/addons/service/locale/icon/icon.png b/packages/addons/service/locale/icon/icon.png new file mode 100644 index 0000000000..90f7acca94 Binary files /dev/null and b/packages/addons/service/locale/icon/icon.png differ diff --git a/packages/addons/service/locale/package.mk b/packages/addons/service/locale/package.mk new file mode 100644 index 0000000000..78a658b62e --- /dev/null +++ b/packages/addons/service/locale/package.mk @@ -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 . +################################################################################ + +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 +} diff --git a/packages/addons/service/locale/resources/settings.xml b/packages/addons/service/locale/resources/settings.xml new file mode 100644 index 0000000000..5157d70e48 --- /dev/null +++ b/packages/addons/service/locale/resources/settings.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/packages/addons/service/locale/source/default.py b/packages/addons/service/locale/source/default.py new file mode 100644 index 0000000000..2ac495b544 --- /dev/null +++ b/packages/addons/service/locale/source/default.py @@ -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 . +################################################################################ + +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() diff --git a/packages/addons/service/locale/source/resources/language/English/strings.po b/packages/addons/service/locale/source/resources/language/English/strings.po new file mode 100644 index 0000000000..eaf9702e63 --- /dev/null +++ b/packages/addons/service/locale/source/resources/language/English/strings.po @@ -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 "" diff --git a/packages/addons/service/locale/source/settings-default.xml b/packages/addons/service/locale/source/settings-default.xml new file mode 100644 index 0000000000..5db70160c9 --- /dev/null +++ b/packages/addons/service/locale/source/settings-default.xml @@ -0,0 +1,4 @@ + + + +