feat(extension): i18n, use meson #18

Merged
kiyui merged 7 commits from meson into main 5 months ago
  1. 5
      .gitignore
  2. 26
      CONTRIBUTING.md
  3. 15
      build-aux/postinstall.py
  4. 11
      data/meson.build
  5. 0
      data/org.gnome.shell.extensions.screenshotlocations.gschema.xml
  6. 36
      meson.build
  7. 41
      package.json
  8. 1
      po/LINGUAS
  9. 4
      po/POTFILES
  10. 1
      po/meson.build
  11. 46
      po/ms.po
  12. 47
      po/screenshotlocations.timur@linux.com.pot
  13. 10
      screenshotlocations.timur@linux.com/metadata.json
  14. 1
      src/extension.js
  15. 20
      src/meson.build
  16. 10
      src/metadata.json.in
  17. 14
      src/prefs.js
  18. 2
      src/prefs.ui
  19. 1240
      yarn.lock

5
.gitignore

@ -1,4 +1 @@
node_modules/
screenshotlocations.timur@linux.com.zip
*.compiled
*.gresource
builddir/

26
CONTRIBUTING.md

@ -3,20 +3,30 @@
- Read the [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md)
- Speak in English, if possible
## Bug Reports & Questions
## Bug Reports, Feature Requests, & Questions
- Fill out the template as best you can
## Code
- Run `yarn install` to set up the Git hooks to perform automated linting
- Otherwise, lint your code manually with [eslint](https://eslint.org/)
- Lint your code with [eslint](https://eslint.org/)
- You agree that your code will be distributed under the [GPL-2.0-or-later](LICENSE)
## Building
- If you do not already have the extension installed locally, you can symlink it with `yarn build:link`
- Run `yarn build:resources` to compile the resources
- Run `yarn build:schema` to compile the resources
- Run `yarn build` to produce a distribution archive
- View the script in `package.json` for building without `yarn`
The extension uses the [meson](https://mesonbuild.com/) build system.
- You can set up a development environment by running `meson setup --prefix=$HOME/.local builddir`
- You can optionally configure the locale path by running `meson setup --prefix=$HOME/.local -Dlocaledir=$HOME/.local/share/gnome-shell/extensions/screenshotlocations.timur@linux.com/locale builddir`
- You can compile and install a build by running `meson install -C builddir`
- Changes to the `meson.build` will require reconfiguring it with `meson --reconfigure builddir`
- You can create a packed extension by running `meson compile extension.zip -C builddir`
### Translations
- Additional files to translate can be added by updating the `po/POTFILES` file
- The translations `.pot` file can be regenerated by running `meson compile screenshotlocations.timur@linux.com-pot -C builddir`
- To add translations for a new language, add the language code to `po/LINGUAS`
- Make sure the language code is unique and sorted by running `cat po/LINGUAS | uniq -u | sort > po/LINGUAS`
- Update the list of `.po` files by running `meson compile screenshotlocations.timur@linux.com-update-po -C builddir`
- For additional help, refer to the [meson localisation guide](https://mesonbuild.com/Localisation.html)

15
build-aux/postinstall.py

@ -0,0 +1,15 @@
#!/usr/bin/env python3
import os
import subprocess
prefix = os.environ.get('MESON_INSTALL_PREFIX', '/usr/local')
datadir = os.path.join(prefix, 'share')
# Packaging tools define DESTDIR and this isn't needed for them
if 'DESTDIR' not in os.environ:
print('Compiling GSettings schemas...')
schemas_dir = os.path.join(datadir, 'glib-2.0', 'schemas')
if not os.path.exists(schemas_dir):
os.makedirs(schemas_dir)
subprocess.call(['glib-compile-schemas', schemas_dir])

11
data/meson.build

@ -0,0 +1,11 @@
gse_schema = files([
gse_prefix + '.gschema.xml',
])
install_data(gse_schema, install_dir: schemadir)
# Test if schema compiles
compile_schemas = find_program('glib-compile-schemas', required: false)
if compile_schemas.found()
test('Validate schema file', compile_schemas, args: ['--strict', '--dry-run', meson.current_source_dir()])
endif

0
screenshotlocations.timur@linux.com/schemas/org.gnome.shell.extensions.screenshotlocations.gschema.xml → data/org.gnome.shell.extensions.screenshotlocations.gschema.xml

36
meson.build

@ -0,0 +1,36 @@
project('screenshotlocations.timur@linux.com',
version: '8',
license: 'GPL2+',
meson_version: '>= 0.50.0')
gnome = import('gnome')
i18n = import('i18n')
# Extension information
gse_uuid = meson.project_name()
gse_prefix = 'org.gnome.shell.extensions.screenshotlocations'
gettext_domain = gse_uuid
# Installation directories
prefixdir = get_option('prefix')
datadir = get_option('datadir')
schemadir = datadir/'glib-2.0'/'schemas'
extensiondir = datadir/'gnome-shell'/'extensions'/gse_uuid
subdir('src')
subdir('data')
subdir('po')
# Create release zip for distribution
custom_target('extension.zip',
command: [
'gnome-extensions', 'pack', prefixdir/extensiondir,
'--extra-source', 'prefs.ui',
'--schema', prefixdir/schemadir/gse_prefix + '.gschema.xml',
'--podir', meson.current_source_dir()/'po',
'--gettext-domain', gettext_domain,
],
output: gse_uuid + '.shell-extension.zip')
# Post-install scripts
meson.add_install_script('build-aux'/'postinstall.py')

41
package.json

@ -1,41 +0,0 @@
{
"name": "gnome-shell-screenshotlocations-extension",
"description": "Change the default GNOME screenshot directory",
"scripts": {
"build:resources": "glib-compile-resources --sourcedir screenshotlocations.timur@linux.com/ screenshotlocations.timur@linux.com/org.gnome.shell.extensions.screenshotlocations.data.gresource.xml",
"build:schema": "glib-compile-schemas screenshotlocations.timur@linux.com/schemas/",
"build:link": "ln -s $(pwd)/screenshotlocations.timur@linux.com/ ~/.local/share/gnome-shell/extensions/",
"build:zip": "cd screenshotlocations.timur@linux.com/ && zip -r ../screenshotlocations.timur@linux.com.zip ./*",
"build": "npm run build:resources && npm run build:schema && npm run build:zip"
},
"repository": {
"type": "git",
"url": "git+https://codeberg.org/kiyui/gnome-shell-screenshotlocations-extension.git"
},
"keywords": [
"gnome",
"gjs",
"screenshot",
"extension"
],
"author": "Dafne Kiyui",
"license": "GPL-2.0",
"bugs": {
"url": "https://codeberg.org/kiyui/gnome-shell-screenshotlocations-extension/issues"
},
"homepage": "https://codeberg.org/kiyui/gnome-shell-screenshotlocations-extension#readme",
"devDependencies": {
"eslint": "^7.8.1",
"husky": ">=4",
"lint-staged": ">=10"
},
"dependencies": {},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": "eslint --fix"
}
}

1
po/LINGUAS

@ -0,0 +1 @@
ms

4
po/POTFILES

@ -0,0 +1,4 @@
src/extension.js
src/prefs.js
src/prefs.ui
data/org.gnome.shell.extensions.screenshotlocations.gschema.xml

1
po/meson.build

@ -0,0 +1 @@
i18n.gettext(gettext_domain, preset: 'glib')

46
po/ms.po

@ -0,0 +1,46 @@
# Malay translations for screenshotlocations.timur@linux.com package.
# Copyright (C) 2021 THE screenshotlocations.timur@linux.com'S COPYRIGHT HOLDER
# This file is distributed under the same license as the screenshotlocations.timur@linux.com package.
# Automatically generated, 2021.
#
msgid ""
msgstr ""
"Project-Id-Version: screenshotlocations.timur@linux.com\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-04-11 00:17+0800\n"
"PO-Revision-Date: 2021-04-10 23:52+0800\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: ms\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ASCII\n"
"Content-Transfer-Encoding: 8bit\n"
#: src/prefs.js:65
#, javascript-format
msgid "Screenshot directory: %s"
msgstr "Direktori tangkapan skrin: %s"
#: src/prefs.ui:28
msgid "Screenshot location"
msgstr "Lokasi tangkapan skrin"
#: src/prefs.ui:39
msgid "No folder selected"
msgstr "Tiada folder yang dipilih"
#: src/prefs.ui:54
msgid "Change"
msgstr "Kemaskini"
#: src/prefs.ui:66
msgid "Select Screenshot Folder"
msgstr "Pilih Folder Tangkapan Skrin"
#: data/org.gnome.shell.extensions.screenshotlocations.gschema.xml:6
msgid "Screenshot directory"
msgstr "Folder tangkapan skrin"
#: data/org.gnome.shell.extensions.screenshotlocations.gschema.xml:7
msgid "Manage where screenshots are saved"
msgstr "Kemaskinikan lokasi pemyimpanan tangkapan skrin"

47
po/screenshotlocations.timur@linux.com.pot

@ -0,0 +1,47 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the screenshotlocations.timur@linux.com package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: screenshotlocations.timur@linux.com\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-04-11 00:17+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: src/prefs.js:65
#, javascript-format
msgid "Screenshot directory: %s"
msgstr ""
#: src/prefs.ui:28
msgid "Screenshot location"
msgstr ""
#: src/prefs.ui:39
msgid "No folder selected"
msgstr ""
#: src/prefs.ui:54
msgid "Change"
msgstr ""
#: src/prefs.ui:66
msgid "Select Screenshot Folder"
msgstr ""
#: data/org.gnome.shell.extensions.screenshotlocations.gschema.xml:6
msgid "Screenshot directory"
msgstr ""
#: data/org.gnome.shell.extensions.screenshotlocations.gschema.xml:7
msgid "Manage where screenshots are saved"
msgstr ""

10
screenshotlocations.timur@linux.com/metadata.json

@ -1,10 +0,0 @@
{
"uuid": "screenshotlocations.timur@linux.com",
"name": "Screenshot Locations",
"description": "Change the default GNOME screenshot directory",
"data-gresource": "org.gnome.shell.extensions.screenshotlocations.data.gresource",
"settings-schema": "org.gnome.shell.extensions.screenshotlocations",
"version": 8,
"shell-version": ["40"],
"url": "https://codeberg.org/kiyui/gnome-shell-screenshotlocations-extension"
}

1
screenshotlocations.timur@linux.com/extension.js → src/extension.js

@ -62,5 +62,6 @@ class Extension {
}
function init() {
ExtensionUtils.initTranslations();
return new Extension();
}

20
src/meson.build

@ -0,0 +1,20 @@
gse_sources = files([
'extension.js',
'prefs.js',
'prefs.ui',
])
# Create metadata file
gse_conf = configuration_data()
gse_conf.set('uuid', gse_uuid)
gse_conf.set('version', meson.project_version())
gse_conf.set('settings_schema', gse_prefix)
gse_conf.set('gettext_domain', gettext_domain)
metadata_json = configure_file(
input: 'metadata.json.in',
output: 'metadata.json',
configuration: gse_conf,
)
gse_sources += metadata_json
install_data(gse_sources, install_dir: extensiondir)

10
src/metadata.json.in

@ -0,0 +1,10 @@
{
"uuid": "@uuid@",
"version": @version@,
"settings-schema": "@settings_schema@",
"gettext-domain": "@gettext_domain@",
"name": "Screenshot Locations",
"description": "Change the default GNOME screenshot directory",
"shell-version": ["40"],
"url": "https://codeberg.org/kiyui/gnome-shell-screenshotlocations-extension"
}

14
screenshotlocations.timur@linux.com/prefs.js → src/prefs.js

@ -18,10 +18,14 @@
/* exported buildPrefsWidget init */
const Gettext = imports.gettext;
const {GObject, GLib, Gio, Gtk} = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Domain = Gettext.domain(Me.metadata.uuid);
const _ = Domain.gettext;
var ScreenshotLocationsExtensionPrefs = GObject.registerClass({
GTypeName: 'ScreenshotLocationsExtensionPrefs',
Template: Me.dir.get_child('prefs.ui').get_uri(),
@ -58,16 +62,16 @@ var ScreenshotLocationsExtensionPrefs = GObject.registerClass({
if (GLib.file_test(p, GLib.FileTest.EXISTS)) {
const file = Gio.File.new_for_path(p);
this._folder_chooser.set_file(file);
this._screenshot_folder_label.set_text('Screenshot directory: %s'.format(p));
this._screenshot_folder_label.set_text(_('Screenshot directory: %s').format(p));
}
}
});
function init() {
// noop
}
function buildPrefsWidget() {
const preferences = ExtensionUtils.getSettings();
return new ScreenshotLocationsExtensionPrefs(preferences);
}
function init() {
ExtensionUtils.initTranslations();
}

2
screenshotlocations.timur@linux.com/prefs.ui → src/prefs.ui

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<interface domain="screenshotlocations.timur@linux.com">
<template class="ScreenshotLocationsExtensionPrefs" parent="GtkBox">
<property name="orientation">vertical</property>
<child>

1240
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save