diff --git a/LICENSE b/LICENSE index 483ea73..a506857 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 deefrawley +Copyright (c) 2023 deefrawley Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,10 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Graduated Cylinder icon by AS Design from the Noun Project -area icon by matteo manenti from the Noun Project -distance icon by Anthony Ledoux from the Noun Project -Weight icon by Adrien Coquet from the Noun Project -Temperature icon by Alexander Skowalsky from the Noun Project +Graduated Cylinder icon by AS Design from Noun Project +Area icon by matteo manenti from Noun Project +Distance icon by Anthony Ledoux from Noun Project +Weight icon by Adrien Coquet from Noun Project +Temperature icon by Alexander Skowalsky from Noun Project +Speed icon by Fahmi Somdi Std from Noun Project +Energy icon by Greg Cresnar from Noun Project diff --git a/README.md b/README.md index b67d681..749b2ce 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) # General Converter (Flow.Launcher.GenConvert) -General weight, volume, distance, area, temperature converter for the [Flow Launcher](https://github.com/Flow-Launcher/Flow.Launcher) +General weight, volume, distance, area, temperature, speed and energy converter for the [Flow Launcher](https://github.com/Flow-Launcher/Flow.Launcher) ### About ### Requirements -Python 3.5 or later. As of Flow Launcher v1.8, Flow should take care of the installation of Python for you if it is not on your system. +Python 3.9 or later. As of Flow Launcher v1.8, Flow should take care of the installation of Python for you if it is not on your system. ### Installing @@ -29,7 +29,10 @@ Currently English and Chinese language supported. Edit the .env file to change t | ------------------------------------------------------------- | -------------------------------------------------- | | `gc ` | Convert the amount of the from unit to the to unit. | -Just entering the keyword will give you the full list of units to choose from in Flow. +The from and to unit are case sensitive. + +Just entering the keyword will give you the full list of units to choose from in Flow. If you want to remove the keyword for this plugin and have it return +results when you simply start entering a number then go to the Plugin settings and turn this helper text off. Entering the keyword, amount and from unit will give you a subset list of units the from unit can be converted to #### Units @@ -41,10 +44,10 @@ The following units and their abbreviations can be used (each table can only con Subject Unit Abbreviation - Distance Logo + Distance Logo - Distance + Distance millimetre mm @@ -56,6 +59,10 @@ The following units and their abbreviations can be used (each table can only con metre m + + decimetre + dm + kilometre km @@ -83,10 +90,10 @@ The following units and their abbreviations can be used (each table can only con Subject Unit Abbreviation - Volume Logo + Volume Logo - Volume + Volume millilitre ml @@ -98,6 +105,10 @@ The following units and their abbreviations can be used (each table can only con litre l + + decalitre + decal + pint US pt @@ -154,6 +165,38 @@ The following units and their abbreviations can be used (each table can only con fluid ounce Imperial flozimp + + cubic decimetre + dm3 + + + cubic millimetre + mm3 + + + cubic centimetre + cm3 + + + cubic metre + m3 + + + cubic inch + in3 + + + cubic feet + ft3 + + + bushel UK + buuk + + + bushel US + buus + @@ -258,6 +301,66 @@ The following units and their abbreviations can be used (each table can only con
+ + + + + + + + + + + + + + + + + + + + +
SubjectUnitAbbreviationSpeed Logo
Speedkilometres per hourkm/h
miles per hourmp/h
knotskt
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SubjectUnitAbbreviationEnergy Logo
Energycaloriescal
kilocalorieskcal
kilojouleskJ
megajoulesMJ
gigajoulesGj
kilowatt hourskWh
British thermal unitsBTU
+ ### Problems, errors and feature requests Open an issue in this repo. diff --git a/SettingsTemplate.yaml b/SettingsTemplate.yaml new file mode 100644 index 0000000..7c05998 --- /dev/null +++ b/SettingsTemplate.yaml @@ -0,0 +1,12 @@ +body: + - type: textBlock + attributes: + name: description + description: > + Convert between different types of units. + - type: checkbox + attributes: + name: show_helper_text + label: "Show helper text of what can be converted" + defaultValue: "true" + description: "If you remove the keyword for this plugin so it triggers on any number then turn this off" diff --git a/assets/Energy.ico b/assets/Energy.ico new file mode 100644 index 0000000..139a6d0 Binary files /dev/null and b/assets/Energy.ico differ diff --git a/assets/Energy.png b/assets/Energy.png new file mode 100644 index 0000000..6e73e1a Binary files /dev/null and b/assets/Energy.png differ diff --git a/assets/Speed.ico b/assets/Speed.ico new file mode 100644 index 0000000..89c1701 Binary files /dev/null and b/assets/Speed.ico differ diff --git a/commands.py b/commands.py index fcc0a20..8ac28e3 100644 --- a/commands.py +++ b/commands.py @@ -2,25 +2,8 @@ import json import os - import click -from plugin import ( - ICON_PATH, - PLUGIN_ACTION_KEYWORD, - PLUGIN_AUTHOR, - PLUGIN_EXECUTE_FILENAME, - PLUGIN_ID, - PLUGIN_PROGRAM_LANG, - PLUGIN_URL, - __long_description__, - __package_name__, - __package_title__, - __short_description__, - __version__, - basedir, -) - @click.group() def translate(): @@ -96,4 +79,4 @@ def gen_plugin_info(): cli = click.CommandCollection(sources=[plugin, translate]) if __name__ == "__main__": - cli() \ No newline at end of file + cli() diff --git a/listfile.txt b/listfile.txt deleted file mode 100644 index 7d3ae8f..0000000 --- a/listfile.txt +++ /dev/null @@ -1,9 +0,0 @@ -.env -main.py -plugin.json -README.MD -requirements.txt -assets\ -plugin\*.py -plugin\translations\en -plugin\translations\zh diff --git a/main.py b/main.py index e1f2066..060ffc0 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ sys.path.append(os.path.join(parent_folder_path, "lib")) sys.path.append(os.path.join(parent_folder_path, "plugin")) -from plugin import Main +from plugin.general_converter import GenConvert if __name__ == "__main__": - Main() \ No newline at end of file + GenConvert() diff --git a/plugin.json b/plugin.json index 3b18e46..2e1b456 100644 --- a/plugin.json +++ b/plugin.json @@ -4,7 +4,7 @@ "Name": "General Converter", "Description": "General weights and measures converter", "Author": "deefrawley", - "Version": "1.1.4", + "Version": "2.0.0", "Language": "python", "Website": "https://github.com/deefrawley/Flow.Launcher.Plugin.GenConvert", "IcoPath": "assets/favicon.ico", diff --git a/plugin/__init__.py b/plugin/__init__.py deleted file mode 100644 index 66b0551..0000000 --- a/plugin/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Currency Converter -===== -Uses the European Central Bank to convert currencies. -""" - - -from plugin.settings import ( - GITHUB_USERNAME, - ICON_PATH, - PLUGIN_ACTION_KEYWORD, - PLUGIN_AUTHOR, - PLUGIN_EXECUTE_FILENAME, - PLUGIN_ID, - PLUGIN_PROGRAM_LANG, - PLUGIN_URL, - __long_description__, - __package_name__, - __package_title__, - __short_description__, - __version__, - basedir, -) -from plugin.ui import Main \ No newline at end of file diff --git a/plugin/extensions.py b/plugin/extensions.py deleted file mode 100644 index 5d07e27..0000000 --- a/plugin/extensions.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- - -import gettext - -from plugin.settings import LOCAL - -# localization -translation = gettext.translation("messages", "plugin/translations/", languages=[LOCAL]) - -_ = translation.gettext \ No newline at end of file diff --git a/plugin/general_converter.py b/plugin/general_converter.py new file mode 100644 index 0000000..d999264 --- /dev/null +++ b/plugin/general_converter.py @@ -0,0 +1,217 @@ +import locale +import textwrap +import re +import units as gc_units + +from translation import _ +from flox import Flox + + +class GenConvert(Flox): + locale.setlocale(locale.LC_NUMERIC, "") + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.logger_level("info") + + def query(self, query): + q = query.strip() + args = q.split(" ") + # Just keyword - show all units if the setting allows + if len(args) == 1: + all_units = get_all_units() + self.add_item( + title=_("General Converter"), + subtitle=_( + " " + ), + ) + if self.settings.get("show_helper_text"): + for cat in all_units: + title = str(cat[0]) + subtitle = ", ".join([str(elem) for elem in cat[1:]]) + lines = textwrap.wrap(subtitle, 110, break_long_words=False) + if len(lines) > 1: + self.add_item( + title=(title), + subtitle=(lines[0]), + icon=f"assets/{title}.ico", + ) + for line in range(1, len(lines)): + self.add_item( + title=(title), + subtitle=(lines[line]), + icon=f"assets/{title}.ico", + ) + else: + self.add_item( + title=(title), + subtitle=(subtitle), + icon=f"assets/{title}.ico", + ) + # Keyword and first unit to convert from - show what it can be converted to + elif len(args) == 2: + hints = get_hints_for_category(args[1]) + self.add_item( + title=_("Available conversions"), + subtitle=(f"{args[0]} {args[1]} to {', '.join(hints)}"), + ) + # Keyword and two units to convert from and to - try to convert + elif len(args) == 3: + try: + # Units are case sensitive. + do_convert = gen_convert(float(args[0]), args[1], args[2]) + if "Error" in do_convert: + if do_convert["Error"] == _("To and from unit is the same"): + self.add_item( + title=_("{}".format(do_convert["Error"])), + subtitle=_("Choose two different units"), + ) + else: + self.add_item( + # f strings seem to break babel so use string formatting instead + title=_("Error - {}").format(do_convert["Error"]), + subtitle=_("Check documentation for accepted units"), + ) + else: + c = do_convert["converted"] + p = smart_precision(locale.localeconv()["decimal_point"], c, 3) + self.add_item( + title=(do_convert["category"]), + subtitle=( + f"{locale.format_string('%.10g', float(args[0]), grouping=True)} {args[1]} = {locale.format_string(f'%.{p}f', c, grouping=True)} {args[2]}" + ), + icon=f"assets/{do_convert['category']}.ico", + ) + do_convert = [] + except Exception as e: + self.add_item(title="Error - {}").format(repr(e), subtitle="") + # Always show the usage while there isn't a valid query + else: + self.add_item( + title=_("General Converter"), + subtitle=_(" "), + ) + + +def get_all_units(short=False): + """Returns all available units as a list of lists by category + + :param short: if True only unit abbreviations are returned, default is False + :type amount: bool + + :rtype: list of lists + :return: A list of lists for each category in units. Index 0 of each internal list + is the category description + """ + + full_list = [] + for u in gc_units.units: + cat_list = [] + cat_list.append(u) + for u2 in gc_units.units[u]: + cat_list.append(u2[0] if short else f"{u2[1]} ({u2[0]})") + full_list.append(cat_list) + return full_list + + +def get_hints_for_category(from_unit: str): + """Takes an input unit and returns a list of units it can be converted to + + :param from_short: unit abbreviation + :type amount: str + + :rtype: list + :return: A list of other unit abbreviations in the same category + """ + c = [] + category = "" + + # Find the category it's in + for u in gc_units.units: + for u2 in gc_units.units[u]: + if u2[0] == from_unit or u2[1] == from_unit or u2[2] == from_unit: + category = str(u) + for uu in gc_units.units[category]: + if uu[0] != from_unit: + c.append(uu[0]) + if category: + return c + else: + return ["no valid units"] + + +def gen_convert(amount: float, from_unit: str, to_unit: str): + """Converts from one unit to another + + :param amount: amount of source unit to convert + :type amount: float + :param from_unit: abbreviation of unit to convert from + :type from_unit: str + :param to_unit: abbreviation of unit to convert to + :type to_unit: str + + :rtype: dict + :return: if to_unit and from_unit are valid returns a dictionary + { + "category":{category of units}, + "converted":{converted amount}, + "fromabbrev":{from unit abbreviation}, + "fromlong":{from unit long name}, + "fromplural":{from unit plural name}, + "toabbrev":{to unit abbreviation}, + "tolong":{to unit long name}, + "toplural":{to unit plural name}, + } + + else returns a dictionary with error status + {"Error": {error text}} + """ + conversions = {} + found_from = found_to = [] + if from_unit == to_unit: + conversions["Error"] = _("To and from unit is the same") + return conversions + for u in gc_units.units: + for u2 in gc_units.units[u]: + if u2[0] == from_unit or u2[1] == from_unit or u2[2] == from_unit: + found_from = u2 + if u2[0] == to_unit or u2[1] == to_unit or u2[2] == to_unit: + found_to = u2 + # If we haven't both in the same category, reset + if found_to and found_from: + found_category = u + break + else: + found_from = found_to = [] + if found_to and found_from: + base_unit_conversion = eval(found_from[3].replace("x", str(amount))) + final_conversion = eval(found_to[4].replace("x", str(base_unit_conversion))) + conversions["category"] = found_category + conversions["converted"] = final_conversion + conversions["fromabbrev"] = found_from[0] + conversions["fromlong"] = found_from[1] + conversions["fromplural"] = found_from[2] + conversions["toabbrev"] = found_to[0] + conversions["tolong"] = found_to[1] + conversions["toplural"] = found_to[2] + + else: + conversions["Error"] = "Problem converting {} and {}".format(from_unit, to_unit) + return conversions + + +def smart_precision(separator, amount, preferred=3): + str_amt = str(amount) + dec_places = str_amt[::-1].find(separator) + # whole number + if dec_places == -1: + return 0 + frac_part = str_amt[-dec_places::] + # fraction is just zeroes + if int(frac_part) == 0: + return 0 + fnz = re.search(r"[1-9]", frac_part).start() + if fnz < preferred: + return preferred + return fnz + 1 diff --git a/plugin/settings.py b/plugin/settings.py deleted file mode 100644 index 690e87b..0000000 --- a/plugin/settings.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding: utf-8 -*- - -import os -from dotenv import load_dotenv - -basedir = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) - -dotenv_path = os.path.join(basedir, ".env") -if os.path.exists(dotenv_path): - load_dotenv(dotenv_path) - - -# The default value can work, if no user config. -LOCAL = os.getenv("local", "en") - - -ICON_PATH = "assets/favicon.ico" - -# the information of package -__package_name__ = "Flow.Launcher.Plugin.GenConvert" -__package_title__ = "General Converter" -__version__ = "1.0.0" -__short_description__ = "General weights and measures converter" -GITHUB_USERNAME = "deefrawley" - - -readme_path = os.path.join(basedir, "README.md") -try: - __long_description__ = open(readme_path, "r").read() -except: - __long_description__ = __short_description__ - - -# other information -PLUGIN_ID = "73f2c04d-176a-4586-9ff5-69fae63321ef" -ICON_PATH = "assets/favicon.ico" -PLUGIN_ACTION_KEYWORD = "gc" -PLUGIN_AUTHOR = "deefrawley" -PLUGIN_PROGRAM_LANG = "python" -PLUGIN_URL = f"https://github.com/{GITHUB_USERNAME}/{__package_name__}" -PLUGIN_EXECUTE_FILENAME = "main.py" diff --git a/plugin/templates.py b/plugin/templates.py deleted file mode 100644 index 670cf02..0000000 --- a/plugin/templates.py +++ /dev/null @@ -1,18 +0,0 @@ -# -*- coding: utf-8 -*- - - -from plugin.settings import ICON_PATH - - -RESULT_TEMPLATE = { - "Title": "", - "SubTitle": "", - "IcoPath": ICON_PATH, -} - -ACTION_TEMPLATE = { - "JsonRPCAction": { - "method": "", - "parameters": [], - } -} \ No newline at end of file diff --git a/plugin/translation.py b/plugin/translation.py new file mode 100644 index 0000000..01c8412 --- /dev/null +++ b/plugin/translation.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +import os +import gettext +from dotenv import load_dotenv + +# TODO - Move language option to Flow setting and remove need for dotenv + +LOCAL = os.getenv("local", "en") + +basedir = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) + +dotenv_path = os.path.join(basedir, ".env") +if os.path.exists(dotenv_path): + load_dotenv(dotenv_path) + +# localization +translation = gettext.translation( + "messages", + os.path.join(basedir, "plugin/translations"), + languages=[LOCAL], +) +translation.install() + +_ = translation.gettext diff --git a/plugin/translations/en/LC_MESSAGES/messages.mo b/plugin/translations/en/LC_MESSAGES/messages.mo index 6158654..68e1222 100644 Binary files a/plugin/translations/en/LC_MESSAGES/messages.mo and b/plugin/translations/en/LC_MESSAGES/messages.mo differ diff --git a/plugin/translations/en/LC_MESSAGES/messages.po b/plugin/translations/en/LC_MESSAGES/messages.po index e2b0cf6..0e06881 100644 --- a/plugin/translations/en/LC_MESSAGES/messages.po +++ b/plugin/translations/en/LC_MESSAGES/messages.po @@ -5,9 +5,9 @@ # msgid "" msgstr "" -"Project-Id-Version: 1.1.3\n" +"Project-Id-Version: 2.0.0\n" "Report-Msgid-Bugs-To: deefrawley@gmail.com\n" -"POT-Creation-Date: 2022-11-08 09:22+1100\n" +"POT-Creation-Date: 2023-04-12 19:52+1000\n" "PO-Revision-Date: 2020-12-13 20:26+1100\n" "Last-Translator: deefrawley \n" "Language: en\n" @@ -18,34 +18,45 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.9.1\n" -#: plugin/ui.py:48 plugin/ui.py:108 +#: plugin/general_converter.py:24 plugin/general_converter.py:92 msgid "General Converter" msgstr "General Converter" -#: plugin/ui.py:49 plugin/ui.py:109 -msgid " " +#: plugin/general_converter.py:25 +#, fuzzy +msgid "" +" " msgstr " " -#: plugin/ui.py:67 +#: plugin/general_converter.py:56 msgid "Available conversions" msgstr "Available conversions" -#: plugin/ui.py:81 +#: plugin/general_converter.py:65 plugin/general_converter.py:173 +msgid "To and from unit is the same" +msgstr "To and from unit is the same" + +#: plugin/general_converter.py:67 msgid "{}" msgstr "{}" -#: plugin/ui.py:82 +#: plugin/general_converter.py:68 msgid "Choose two different units" msgstr "Choose two different units" -#: plugin/ui.py:87 plugin/ui.py:104 +#: plugin/general_converter.py:73 msgid "Error - {}" msgstr "Error - {}" -#: plugin/ui.py:88 +#: plugin/general_converter.py:74 msgid "Check documentation for accepted units" msgstr "Check documentation for accepted units" +#: plugin/general_converter.py:93 +msgid " " +msgstr " " + #: plugin/units.py:20 msgid "Distance" msgstr "Distance" @@ -59,343 +70,516 @@ msgid "metres" msgstr "metres" #: plugin/units.py:24 +#, fuzzy +msgid "decimetre" +msgstr "centimetre" + +#: plugin/units.py:24 +#, fuzzy +msgid "decimetres" +msgstr "centimetres" + +#: plugin/units.py:25 msgid "millimetre" msgstr "millimetre" -#: plugin/units.py:24 +#: plugin/units.py:25 msgid "millimetres" msgstr "millimetres" -#: plugin/units.py:25 +#: plugin/units.py:26 msgid "centimetre" msgstr "centimetre" -#: plugin/units.py:25 +#: plugin/units.py:26 msgid "centimetres" msgstr "centimetres" -#: plugin/units.py:26 +#: plugin/units.py:27 msgid "kilometre" msgstr "kilometre" -#: plugin/units.py:26 +#: plugin/units.py:27 msgid "kilometres" msgstr "kilometres" -#: plugin/units.py:27 +#: plugin/units.py:28 msgid "inch" msgstr "inch" -#: plugin/units.py:27 +#: plugin/units.py:28 msgid "inches" msgstr "inches" -#: plugin/units.py:28 +#: plugin/units.py:29 msgid "foot" msgstr "foot" -#: plugin/units.py:28 +#: plugin/units.py:29 msgid "feet" msgstr "feet" -#: plugin/units.py:29 +#: plugin/units.py:30 msgid "yard" msgstr "yard" -#: plugin/units.py:29 +#: plugin/units.py:30 msgid "yards" msgstr "yards" -#: plugin/units.py:30 +#: plugin/units.py:31 msgid "mile" msgstr "mile" -#: plugin/units.py:30 +#: plugin/units.py:31 msgid "miles" msgstr "miles" -#: plugin/units.py:32 +#: plugin/units.py:33 msgid "Volume" msgstr "Volume" -#: plugin/units.py:37 +#: plugin/units.py:38 msgid "millilitre" msgstr "millilitre" -#: plugin/units.py:37 +#: plugin/units.py:38 msgid "millilitres" msgstr "millilitres" -#: plugin/units.py:39 plugin/units.py:160 +#: plugin/units.py:40 plugin/units.py:218 msgid "gram" msgstr "gram" -#: plugin/units.py:39 plugin/units.py:160 +#: plugin/units.py:40 plugin/units.py:218 msgid "grams" msgstr "grams" -#: plugin/units.py:40 +#: plugin/units.py:41 msgid "litre" msgstr "litre" -#: plugin/units.py:40 +#: plugin/units.py:41 msgid "litres" msgstr "litres" -#: plugin/units.py:41 +#: plugin/units.py:42 +#, fuzzy +msgid "decalitre" +msgstr "litre" + +#: plugin/units.py:42 +#, fuzzy +msgid "decalitres" +msgstr "litres" + +#: plugin/units.py:43 msgid "pint US" msgstr "pint US" -#: plugin/units.py:41 +#: plugin/units.py:43 msgid "pints US" msgstr "pints US" -#: plugin/units.py:44 +#: plugin/units.py:46 msgid "pint Imperial" msgstr "pint Imperial" -#: plugin/units.py:45 +#: plugin/units.py:47 msgid "pints Imperial" msgstr "pints Imperial" -#: plugin/units.py:49 +#: plugin/units.py:51 msgid "quart US" msgstr "quart US" -#: plugin/units.py:49 +#: plugin/units.py:51 msgid "quarts US" msgstr "quarts US" -#: plugin/units.py:52 +#: plugin/units.py:54 msgid "quart Imperial" msgstr "quart Imperial" -#: plugin/units.py:53 +#: plugin/units.py:55 msgid "quarts Imperial" msgstr "quarts Imperial" -#: plugin/units.py:59 +#: plugin/units.py:61 msgid "cup US" msgstr "cup US" -#: plugin/units.py:60 +#: plugin/units.py:62 msgid "cups US" msgstr "cups US" -#: plugin/units.py:66 +#: plugin/units.py:68 msgid "cup Imperial" msgstr "cup Imperial" -#: plugin/units.py:67 +#: plugin/units.py:69 msgid "cups Imperial" msgstr "cups Imperial" -#: plugin/units.py:73 +#: plugin/units.py:75 msgid "tablespoon US" msgstr "tablespoon US" -#: plugin/units.py:74 +#: plugin/units.py:76 msgid "tabelspoons US" msgstr "tabelspoons US" -#: plugin/units.py:80 +#: plugin/units.py:82 msgid "tablespoon Imperial" msgstr "tablespoon Imperial" -#: plugin/units.py:81 +#: plugin/units.py:83 msgid "tabelspoons Imperial" msgstr "tabelspoons Imperial" -#: plugin/units.py:87 +#: plugin/units.py:89 msgid "teaspoon US" msgstr "teaspoon US" -#: plugin/units.py:88 +#: plugin/units.py:90 msgid "teaspoons US" msgstr "teaspoons US" -#: plugin/units.py:94 +#: plugin/units.py:96 msgid "teaspoon Imperial" msgstr "teaspoon Imperial" -#: plugin/units.py:95 +#: plugin/units.py:97 msgid "teaspoons Imperial" msgstr "teaspoons Imperial" -#: plugin/units.py:101 +#: plugin/units.py:103 msgid "gallon US" msgstr "gallon US" -#: plugin/units.py:102 +#: plugin/units.py:104 msgid "gallons US" msgstr "gallons US" -#: plugin/units.py:108 +#: plugin/units.py:110 msgid "gallon Imperial" msgstr "gallon Imperial" -#: plugin/units.py:109 +#: plugin/units.py:111 msgid "gallons Imperial" msgstr "gallons Imperial" -#: plugin/units.py:115 +#: plugin/units.py:117 msgid "fluid ounce US" msgstr "fluid ounce US" -#: plugin/units.py:116 +#: plugin/units.py:118 msgid "fluid ounces US" msgstr "fluid ounces US" -#: plugin/units.py:122 +#: plugin/units.py:124 msgid "fluid ounce Imperial" msgstr "fluid ounce Imperial" -#: plugin/units.py:123 +#: plugin/units.py:125 msgid "fluid ounces Imperial" msgstr "fluid ounces Imperial" -#: plugin/units.py:130 +#: plugin/units.py:131 +#, fuzzy +msgid "cubic decimetre" +msgstr "centimetre" + +#: plugin/units.py:132 +#, fuzzy +msgid "cubic decimetres" +msgstr "centimetres" + +#: plugin/units.py:138 +#, fuzzy +msgid "cubic millimetre" +msgstr "millimetre" + +#: plugin/units.py:139 +#, fuzzy +msgid "cubic millimetres" +msgstr "millimetres" + +#: plugin/units.py:145 +#, fuzzy +msgid "cubic centimetre" +msgstr "centimetre" + +#: plugin/units.py:146 +#, fuzzy +msgid "cubic centimetres" +msgstr "centimetres" + +#: plugin/units.py:152 +#, fuzzy +msgid "cubic metre" +msgstr "centimetre" + +#: plugin/units.py:153 +#, fuzzy +msgid "cubic metres" +msgstr "centimetres" + +#: plugin/units.py:159 +msgid "cubic inch" +msgstr "" + +#: plugin/units.py:160 +#, fuzzy +msgid "cubic inches" +msgstr "inches" + +#: plugin/units.py:166 plugin/units.py:167 +msgid "cubic feet" +msgstr "" + +#: plugin/units.py:173 +msgid "bushel UK" +msgstr "" + +#: plugin/units.py:174 +msgid "bushels UK" +msgstr "" + +#: plugin/units.py:180 +msgid "bushel US" +msgstr "" + +#: plugin/units.py:181 +msgid "bushels US" +msgstr "" + +#: plugin/units.py:188 msgid "square metre" msgstr "square metre" -#: plugin/units.py:130 +#: plugin/units.py:188 msgid "square metres" msgstr "square metres" -#: plugin/units.py:131 +#: plugin/units.py:189 msgid "hectare" msgstr "hectare" -#: plugin/units.py:131 +#: plugin/units.py:189 msgid "hectares" msgstr "hectares" -#: plugin/units.py:132 +#: plugin/units.py:190 msgid "acre" msgstr "acre" -#: plugin/units.py:132 +#: plugin/units.py:190 msgid "acres" msgstr "acres" -#: plugin/units.py:135 +#: plugin/units.py:193 msgid "square centimetre" msgstr "square centimetre" -#: plugin/units.py:136 +#: plugin/units.py:194 msgid "square centimetres" msgstr "square centimetres" -#: plugin/units.py:142 +#: plugin/units.py:200 msgid "square kilometre" msgstr "square kilometre" -#: plugin/units.py:143 +#: plugin/units.py:201 msgid "square kilometres" msgstr "square kilometres" -#: plugin/units.py:147 +#: plugin/units.py:205 msgid "square inch" msgstr "square inch" -#: plugin/units.py:147 +#: plugin/units.py:205 msgid "square inches" msgstr "square inches" -#: plugin/units.py:150 +#: plugin/units.py:208 msgid "square mile" msgstr "square mile" -#: plugin/units.py:151 +#: plugin/units.py:209 msgid "square miles" msgstr "square miles" -#: plugin/units.py:155 +#: plugin/units.py:213 msgid "square foot" msgstr "square foot" -#: plugin/units.py:155 +#: plugin/units.py:213 msgid "square feet" msgstr "square feet" -#: plugin/units.py:156 +#: plugin/units.py:214 msgid "square yard" msgstr "square yard" -#: plugin/units.py:156 +#: plugin/units.py:214 msgid "square yards" msgstr "square yards" -#: plugin/units.py:162 +#: plugin/units.py:220 msgid "kilogram" msgstr "kilogram" -#: plugin/units.py:162 +#: plugin/units.py:220 msgid "kilograms" msgstr "kilograms" -#: plugin/units.py:163 +#: plugin/units.py:221 msgid "pound" msgstr "pound" -#: plugin/units.py:163 +#: plugin/units.py:221 msgid "pounds" msgstr "pounds" -#: plugin/units.py:164 +#: plugin/units.py:222 msgid "ounce" msgstr "ounce" -#: plugin/units.py:164 +#: plugin/units.py:222 msgid "ounces" msgstr "ounces" -#: plugin/units.py:165 +#: plugin/units.py:223 msgid "stone" msgstr "stone" -#: plugin/units.py:168 +#: plugin/units.py:226 msgid "tonne" msgstr "tonne" -#: plugin/units.py:169 +#: plugin/units.py:227 msgid "tonnes" msgstr "tonnes" -#: plugin/units.py:175 +#: plugin/units.py:233 msgid "US ton" msgstr "US ton" -#: plugin/units.py:176 +#: plugin/units.py:234 msgid "US tons" msgstr "US tons" -#: plugin/units.py:182 +#: plugin/units.py:240 msgid "Imperial ton" msgstr "Imperial ton" -#: plugin/units.py:183 +#: plugin/units.py:241 msgid "Imperial tons" msgstr "Imperial tons" -#: plugin/units.py:190 +#: plugin/units.py:248 msgid "Celsius" msgstr "Celsius" -#: plugin/units.py:192 +#: plugin/units.py:250 msgid "Farenheit" msgstr "Farenheit" -#: plugin/units.py:193 +#: plugin/units.py:251 msgid "Kelvin" msgstr "Kelvin" -#: plugin/utils.py:82 -msgid "To and from unit is the same" -msgstr "To and from unit is the same" +#: plugin/units.py:255 +#, fuzzy +msgid "kilometres per hour" +msgstr "kilometres" + +#: plugin/units.py:258 plugin/units.py:259 +msgid "metres per second" +msgstr "" + +#: plugin/units.py:265 plugin/units.py:266 +msgid "miles per hour" +msgstr "" + +#: plugin/units.py:272 +msgid "knot" +msgstr "" + +#: plugin/units.py:273 +msgid "knots" +msgstr "" + +#: plugin/units.py:280 +#, fuzzy +msgid "joule" +msgstr "ounce" + +#: plugin/units.py:280 +#, fuzzy +msgid "joules" +msgstr "ounces" + +#: plugin/units.py:283 +msgid "calorie" +msgstr "" + +#: plugin/units.py:284 +#, fuzzy +msgid "calories" +msgstr "hectares" + +#: plugin/units.py:290 +msgid "kilocalorie" +msgstr "" + +#: plugin/units.py:291 +#, fuzzy +msgid "kilocalories" +msgstr "kilometres" + +#: plugin/units.py:297 +msgid "kilojoule" +msgstr "" + +#: plugin/units.py:298 +#, fuzzy +msgid "kilojoules" +msgstr "kilometres" + +#: plugin/units.py:304 +msgid "megajoule" +msgstr "" + +#: plugin/units.py:305 +msgid "megajoules" +msgstr "" + +#: plugin/units.py:311 +msgid "gigajoule" +msgstr "" + +#: plugin/units.py:312 +msgid "gigajoules" +msgstr "" + +#: plugin/units.py:318 +msgid "kilowatt hour" +msgstr "" + +#: plugin/units.py:319 +msgid "kilowatt hours" +msgstr "" + +#: plugin/units.py:325 +msgid "British thermal unit" +msgstr "" -#: plugin/utils.py:110 -msgid "Problem converting {} and {}" -msgstr "Problem converting {} and {}" +#: plugin/units.py:326 +msgid "British thermal units" +msgstr "" +#~ msgid "Problem converting {} and {}" +#~ msgstr "Problem converting {} and {}" diff --git a/plugin/translations/zh/LC_MESSAGES/messages.mo b/plugin/translations/zh/LC_MESSAGES/messages.mo index 8365bb6..b646cd1 100644 Binary files a/plugin/translations/zh/LC_MESSAGES/messages.mo and b/plugin/translations/zh/LC_MESSAGES/messages.mo differ diff --git a/plugin/translations/zh/LC_MESSAGES/messages.po b/plugin/translations/zh/LC_MESSAGES/messages.po index 2510fd2..a7f3aa3 100644 --- a/plugin/translations/zh/LC_MESSAGES/messages.po +++ b/plugin/translations/zh/LC_MESSAGES/messages.po @@ -5,9 +5,9 @@ # msgid "" msgstr "" -"Project-Id-Version: 1.1.3\n" +"Project-Id-Version: 2.0.0\n" "Report-Msgid-Bugs-To: deefrawley@gmail.com\n" -"POT-Creation-Date: 2022-11-08 09:22+1100\n" +"POT-Creation-Date: 2023-04-12 19:52+1000\n" "PO-Revision-Date: 2021-06-07 15:16+1000\n" "Last-Translator: deefrawley \n" "Language: zh\n" @@ -18,34 +18,45 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.9.1\n" -#: plugin/ui.py:48 plugin/ui.py:108 +#: plugin/general_converter.py:24 plugin/general_converter.py:92 msgid "General Converter" msgstr "通用单位换算器" -#: plugin/ui.py:49 plugin/ui.py:109 -msgid " " +#: plugin/general_converter.py:25 +#, fuzzy +msgid "" +" " msgstr "<热键> <量> <源单元> <目的地单位>" -#: plugin/ui.py:67 +#: plugin/general_converter.py:56 msgid "Available conversions" msgstr "可用转换" -#: plugin/ui.py:81 +#: plugin/general_converter.py:65 plugin/general_converter.py:173 +msgid "To and from unit is the same" +msgstr "源单元和目标单元相同" + +#: plugin/general_converter.py:67 msgid "{}" msgstr "" -#: plugin/ui.py:82 +#: plugin/general_converter.py:68 msgid "Choose two different units" msgstr "选择两个不同的单位" -#: plugin/ui.py:87 plugin/ui.py:104 +#: plugin/general_converter.py:73 msgid "Error - {}" msgstr "错误 - {}" -#: plugin/ui.py:88 +#: plugin/general_converter.py:74 msgid "Check documentation for accepted units" msgstr "检查文档以获取正确的度量单位" +#: plugin/general_converter.py:93 +msgid " " +msgstr "<热键> <量> <源单元> <目的地单位>" + #: plugin/units.py:20 msgid "Distance" msgstr "距离" @@ -59,343 +70,516 @@ msgid "metres" msgstr "仪表" #: plugin/units.py:24 +#, fuzzy +msgid "decimetre" +msgstr "厘米" + +#: plugin/units.py:24 +#, fuzzy +msgid "decimetres" +msgstr "厘米" + +#: plugin/units.py:25 msgid "millimetre" msgstr "毫米" -#: plugin/units.py:24 +#: plugin/units.py:25 msgid "millimetres" msgstr "毫米" -#: plugin/units.py:25 +#: plugin/units.py:26 msgid "centimetre" msgstr "厘米" -#: plugin/units.py:25 +#: plugin/units.py:26 msgid "centimetres" msgstr "厘米" -#: plugin/units.py:26 +#: plugin/units.py:27 msgid "kilometre" msgstr "公里" -#: plugin/units.py:26 +#: plugin/units.py:27 msgid "kilometres" msgstr "公里" -#: plugin/units.py:27 +#: plugin/units.py:28 msgid "inch" msgstr "英寸" -#: plugin/units.py:27 +#: plugin/units.py:28 msgid "inches" msgstr "英寸" -#: plugin/units.py:28 +#: plugin/units.py:29 msgid "foot" msgstr "丈" -#: plugin/units.py:28 +#: plugin/units.py:29 msgid "feet" msgstr "丈" -#: plugin/units.py:29 +#: plugin/units.py:30 msgid "yard" msgstr "码尺" -#: plugin/units.py:29 +#: plugin/units.py:30 msgid "yards" msgstr "码尺" -#: plugin/units.py:30 +#: plugin/units.py:31 msgid "mile" msgstr "英里" -#: plugin/units.py:30 +#: plugin/units.py:31 msgid "miles" msgstr "英里" -#: plugin/units.py:32 +#: plugin/units.py:33 msgid "Volume" msgstr "量" -#: plugin/units.py:37 +#: plugin/units.py:38 msgid "millilitre" msgstr "毫升" -#: plugin/units.py:37 +#: plugin/units.py:38 msgid "millilitres" msgstr "毫升" -#: plugin/units.py:39 plugin/units.py:160 +#: plugin/units.py:40 plugin/units.py:218 msgid "gram" msgstr "公克" -#: plugin/units.py:39 plugin/units.py:160 +#: plugin/units.py:40 plugin/units.py:218 msgid "grams" msgstr "公克" -#: plugin/units.py:40 +#: plugin/units.py:41 msgid "litre" msgstr "升" -#: plugin/units.py:40 +#: plugin/units.py:41 msgid "litres" msgstr "升" -#: plugin/units.py:41 +#: plugin/units.py:42 +#, fuzzy +msgid "decalitre" +msgstr "升" + +#: plugin/units.py:42 +#, fuzzy +msgid "decalitres" +msgstr "升" + +#: plugin/units.py:43 msgid "pint US" msgstr "品脱 US" -#: plugin/units.py:41 +#: plugin/units.py:43 msgid "pints US" msgstr "品脱 US" -#: plugin/units.py:44 +#: plugin/units.py:46 msgid "pint Imperial" msgstr "英品脱" -#: plugin/units.py:45 +#: plugin/units.py:47 msgid "pints Imperial" msgstr "英品脱" -#: plugin/units.py:49 +#: plugin/units.py:51 msgid "quart US" msgstr "夸脱 US" -#: plugin/units.py:49 +#: plugin/units.py:51 msgid "quarts US" msgstr "夸脱 US" -#: plugin/units.py:52 +#: plugin/units.py:54 msgid "quart Imperial" msgstr "英夸脱" -#: plugin/units.py:53 +#: plugin/units.py:55 msgid "quarts Imperial" msgstr "英夸脱" -#: plugin/units.py:59 +#: plugin/units.py:61 msgid "cup US" msgstr "杯 US" -#: plugin/units.py:60 +#: plugin/units.py:62 msgid "cups US" msgstr "杯 US" -#: plugin/units.py:66 +#: plugin/units.py:68 msgid "cup Imperial" msgstr "英杯" -#: plugin/units.py:67 +#: plugin/units.py:69 msgid "cups Imperial" msgstr "英杯" -#: plugin/units.py:73 +#: plugin/units.py:75 msgid "tablespoon US" msgstr "汤匙 US" -#: plugin/units.py:74 +#: plugin/units.py:76 msgid "tabelspoons US" msgstr "汤匙 US" -#: plugin/units.py:80 +#: plugin/units.py:82 msgid "tablespoon Imperial" msgstr "英汤匙" -#: plugin/units.py:81 +#: plugin/units.py:83 msgid "tabelspoons Imperial" msgstr "英汤匙" -#: plugin/units.py:87 +#: plugin/units.py:89 msgid "teaspoon US" msgstr "茶匙 US" -#: plugin/units.py:88 +#: plugin/units.py:90 msgid "teaspoons US" msgstr "茶匙 US" -#: plugin/units.py:94 +#: plugin/units.py:96 msgid "teaspoon Imperial" msgstr "英茶匙" -#: plugin/units.py:95 +#: plugin/units.py:97 msgid "teaspoons Imperial" msgstr "英茶匙" -#: plugin/units.py:101 +#: plugin/units.py:103 msgid "gallon US" msgstr "加仑 US" -#: plugin/units.py:102 +#: plugin/units.py:104 msgid "gallons US" msgstr "加仑 US" -#: plugin/units.py:108 +#: plugin/units.py:110 msgid "gallon Imperial" msgstr "英加仑" -#: plugin/units.py:109 +#: plugin/units.py:111 msgid "gallons Imperial" msgstr "英加仑" -#: plugin/units.py:115 +#: plugin/units.py:117 msgid "fluid ounce US" msgstr "液盎司 US" -#: plugin/units.py:116 +#: plugin/units.py:118 msgid "fluid ounces US" msgstr "液盎司 US" -#: plugin/units.py:122 +#: plugin/units.py:124 msgid "fluid ounce Imperial" msgstr "英液盎司" -#: plugin/units.py:123 +#: plugin/units.py:125 msgid "fluid ounces Imperial" msgstr "英液盎司" -#: plugin/units.py:130 +#: plugin/units.py:131 +#, fuzzy +msgid "cubic decimetre" +msgstr "立方分米" + +#: plugin/units.py:132 +#, fuzzy +msgid "cubic decimetres" +msgstr "立方分米" + +#: plugin/units.py:138 +#, fuzzy +msgid "cubic millimetre" +msgstr "立方毫米" + +#: plugin/units.py:139 +#, fuzzy +msgid "cubic millimetres" +msgstr "立方毫米" + +#: plugin/units.py:145 +#, fuzzy +msgid "cubic centimetre" +msgstr "立方厘米" + +#: plugin/units.py:146 +#, fuzzy +msgid "cubic centimetres" +msgstr "立方厘米" + +#: plugin/units.py:152 +#, fuzzy +msgid "cubic metre" +msgstr "立方米" + +#: plugin/units.py:153 +#, fuzzy +msgid "cubic metres" +msgstr "立方米" + +#: plugin/units.py:159 +msgid "cubic inch" +msgstr "立方英寸" + +#: plugin/units.py:160 +#, fuzzy +msgid "cubic inches" +msgstr "英寸" + +#: plugin/units.py:166 plugin/units.py:167 +msgid "cubic feet" +msgstr "立方英尺" + +#: plugin/units.py:173 +msgid "bushel UK" +msgstr "蒲式耳 英国" + +#: plugin/units.py:174 +msgid "bushels UK" +msgstr "蒲式耳 英国" + +#: plugin/units.py:180 +msgid "bushel US" +msgstr "蒲式耳 美国" + +#: plugin/units.py:181 +msgid "bushels US" +msgstr "蒲式耳 美国" + +#: plugin/units.py:188 msgid "square metre" msgstr "平方米" -#: plugin/units.py:130 +#: plugin/units.py:188 msgid "square metres" msgstr "平方米" -#: plugin/units.py:131 +#: plugin/units.py:189 msgid "hectare" msgstr "公顷" -#: plugin/units.py:131 +#: plugin/units.py:189 msgid "hectares" msgstr "公顷" -#: plugin/units.py:132 +#: plugin/units.py:190 msgid "acre" msgstr "英亩" -#: plugin/units.py:132 +#: plugin/units.py:190 msgid "acres" msgstr "英亩" -#: plugin/units.py:135 +#: plugin/units.py:193 msgid "square centimetre" msgstr "平方厘米" -#: plugin/units.py:136 +#: plugin/units.py:194 msgid "square centimetres" msgstr "平方厘米" -#: plugin/units.py:142 +#: plugin/units.py:200 msgid "square kilometre" msgstr "平方公里" -#: plugin/units.py:143 +#: plugin/units.py:201 msgid "square kilometres" msgstr "平方公里" -#: plugin/units.py:147 +#: plugin/units.py:205 msgid "square inch" msgstr "平方英寸" -#: plugin/units.py:147 +#: plugin/units.py:205 msgid "square inches" msgstr "平方英寸" -#: plugin/units.py:150 +#: plugin/units.py:208 msgid "square mile" msgstr "平方英里" -#: plugin/units.py:151 +#: plugin/units.py:209 msgid "square miles" msgstr "平方英里" -#: plugin/units.py:155 +#: plugin/units.py:213 msgid "square foot" msgstr "平方英尺" -#: plugin/units.py:155 +#: plugin/units.py:213 msgid "square feet" msgstr "平方英尺" -#: plugin/units.py:156 +#: plugin/units.py:214 msgid "square yard" msgstr "平方码" -#: plugin/units.py:156 +#: plugin/units.py:214 msgid "square yards" msgstr "平方码" -#: plugin/units.py:162 +#: plugin/units.py:220 msgid "kilogram" msgstr "公斤" -#: plugin/units.py:162 +#: plugin/units.py:220 msgid "kilograms" msgstr "公斤" -#: plugin/units.py:163 +#: plugin/units.py:221 msgid "pound" msgstr "磅" -#: plugin/units.py:163 +#: plugin/units.py:221 msgid "pounds" msgstr "磅" -#: plugin/units.py:164 +#: plugin/units.py:222 msgid "ounce" msgstr "盎司" -#: plugin/units.py:164 +#: plugin/units.py:222 msgid "ounces" msgstr "盎司" -#: plugin/units.py:165 +#: plugin/units.py:223 msgid "stone" msgstr "石头" -#: plugin/units.py:168 +#: plugin/units.py:226 msgid "tonne" msgstr "公吨" -#: plugin/units.py:169 +#: plugin/units.py:227 msgid "tonnes" msgstr "公吨" -#: plugin/units.py:175 +#: plugin/units.py:233 msgid "US ton" msgstr "美吨" -#: plugin/units.py:176 +#: plugin/units.py:234 msgid "US tons" msgstr "美吨" -#: plugin/units.py:182 +#: plugin/units.py:240 msgid "Imperial ton" msgstr "英制吨" -#: plugin/units.py:183 +#: plugin/units.py:241 msgid "Imperial tons" msgstr "英制吨" -#: plugin/units.py:190 +#: plugin/units.py:248 msgid "Celsius" msgstr "摄氏" -#: plugin/units.py:192 +#: plugin/units.py:250 msgid "Farenheit" msgstr "华氏度" -#: plugin/units.py:193 +#: plugin/units.py:251 msgid "Kelvin" msgstr "开尔文" -#: plugin/utils.py:82 -msgid "To and from unit is the same" -msgstr "源单元和目标单元相同" +#: plugin/units.py:255 +#, fuzzy +msgid "kilometres per hour" +msgstr "公里每小时" + +#: plugin/units.py:258 plugin/units.py:259 +msgid "metres per second" +msgstr "米每秒" + +#: plugin/units.py:265 plugin/units.py:266 +msgid "miles per hour" +msgstr "英里每小时" + +#: plugin/units.py:272 +msgid "knot" +msgstr "海里" + +#: plugin/units.py:273 +msgid "knots" +msgstr "海里" + +#: plugin/units.py:280 +#, fuzzy +msgid "joule" +msgstr "焦耳" + +#: plugin/units.py:280 +#, fuzzy +msgid "joules" +msgstr "焦耳" + +#: plugin/units.py:283 +msgid "calorie" +msgstr "卡路里" + +#: plugin/units.py:284 +#, fuzzy +msgid "calories" +msgstr "卡路里" + +#: plugin/units.py:290 +msgid "kilocalorie" +msgstr "大卡" + +#: plugin/units.py:291 +#, fuzzy +msgid "kilocalories" +msgstr "大卡" + +#: plugin/units.py:297 +msgid "kilojoule" +msgstr "" + +#: plugin/units.py:298 +#, fuzzy +msgid "kilojoules" +msgstr "千焦耳" + +#: plugin/units.py:304 +msgid "megajoule" +msgstr "兆焦耳" + +#: plugin/units.py:305 +msgid "megajoules" +msgstr "兆焦耳" + +#: plugin/units.py:311 +msgid "gigajoule" +msgstr "千兆焦耳" + +#: plugin/units.py:312 +msgid "gigajoules" +msgstr "千兆焦耳" + +#: plugin/units.py:318 +msgid "kilowatt hour" +msgstr "" + +#: plugin/units.py:319 +msgid "kilowatt hours" +msgstr "千瓦时" + +#: plugin/units.py:325 +msgid "British thermal unit" +msgstr "英国热量单位" -#: plugin/utils.py:110 -msgid "Problem converting {} and {}" -msgstr "转换问题 {} 和 {}" +#: plugin/units.py:326 +msgid "British thermal units" +msgstr "英国热量单位" +#~ msgid "Problem converting {} and {}" +#~ msgstr "转换问题 {} 和 {}" diff --git a/plugin/ui.py b/plugin/ui.py deleted file mode 100644 index 287e05d..0000000 --- a/plugin/ui.py +++ /dev/null @@ -1,111 +0,0 @@ -# -*- coding: utf-8 -*- -import textwrap -import copy -import locale -import plugin.utils - -from typing import List -from plugin.templates import RESULT_TEMPLATE, ACTION_TEMPLATE -from flowlauncher import FlowLauncher -from plugin.extensions import _ - - -class Main(FlowLauncher): - messages_queue = [] - locale.setlocale(locale.LC_NUMERIC, "") - - def sendNormalMess( - self, title: str, subtitle: str, iconpath: str = "assets/favicon.ico" - ): - message = copy.deepcopy(RESULT_TEMPLATE) - message["Title"] = title - message["SubTitle"] = subtitle - message["IcoPath"] = iconpath - - self.messages_queue.append(message) - - def sendActionMess(self, title: str, subtitle: str, method: str, value: List): - # information - message = copy.deepcopy(RESULT_TEMPLATE) - message["Title"] = title - message["SubTitle"] = subtitle - - # action - action = copy.deepcopy(ACTION_TEMPLATE) - action["JsonRPCAction"]["method"] = method - action["JsonRPCAction"]["parameters"] = value - message.update(action) - - self.messages_queue.append(message) - - def query(self, param: str) -> List[dict]: - q = param.strip() - args = q.split(" ") - # Just keyword - show all units - if len(args) == 1: - all_units = plugin.utils.get_all_units() - self.sendNormalMess( - (_("General Converter")), - _(" "), - ) - for cat in all_units: - title = str(cat[0]) - subtitle = ", ".join([str(elem) for elem in cat[1:]]) - lines = textwrap.wrap(subtitle, 110, break_long_words=False) - if len(lines) > 1: - self.sendNormalMess((title), (lines[0]), f"assets/{title}.ico") - for line in range(1, len(lines)): - self.sendNormalMess( - (title), (lines[line]), f"assets/{title}.ico" - ) - else: - self.sendNormalMess((title), (subtitle), f"assets/{title}.ico") - # Keyword and first unit to convert from - show what it can be converted to - elif len(args) == 2: - hints = plugin.utils.get_hints_for_category(args[1].lower()) - self.sendNormalMess( - _("Available conversions"), - (f"{args[0]} {args[1]} to {', '.join(hints)}"), - ) - # Keyword and two units to convert from and to - try to convert - elif len(args) == 3: - try: - # Units are currently case insensitive. May need to change this if in future new units - # with official upper case shorthand are catered for - args[1] = args[1].lower() - args[2] = args[2].lower() - do_convert = plugin.utils.gen_convert(float(args[0]), args[1], args[2]) - if "Error" in do_convert: - if do_convert["Error"] == "To and from unit is the same": - self.sendNormalMess( - _("{}".format(do_convert["Error"])), - _("Choose two different units"), - ) - else: - self.sendNormalMess( - # f strings seem to break babel so use string formatting instead - _("Error - {}").format(do_convert["Error"]), - _("Check documentation for accepted units"), - ) - else: - c = do_convert["converted"] - p = plugin.utils.smart_precision( - locale.localeconv()["decimal_point"], c, 3 - ) - self.sendNormalMess( - (do_convert["category"]), - ( - f"{locale.format_string('%.10g', float(args[0]), grouping=True)} {args[1]} = {locale.format_string(f'%.{p}f', c, grouping=True)} {args[2]}" - ), - f"assets/{do_convert['category']}.ico", - ) - do_convert = [] - except Exception as e: - self.sendNormalMess(_("Error - {}").format(repr(e)), "") - # Always show the usage while there isn't a valid query - else: - self.sendNormalMess( - _("General Converter"), - _(" "), - ) - return self.messages_queue diff --git a/plugin/units.py b/plugin/units.py index fe222c5..1c37a52 100644 --- a/plugin/units.py +++ b/plugin/units.py @@ -1,4 +1,4 @@ -from plugin.extensions import _ +from translation import _ """ Unit Syntax: @@ -21,6 +21,7 @@ # Base ["m", _("metre"), _("metres"), "x * 1", "x * 1"], # All below convert to/from base + ["dm", _("decimetre"), _("decimetres"), "x / 10", "x * 10"], ["mm", _("millimetre"), _("millimetres"), "x / 1000", "x * 1000"], ["cm", _("centimetre"), _("centimetres"), "x / 100", "x * 100"], ["km", _("kilometre"), _("kilometres"), "x / 0.001", "x * 0.001"], @@ -38,6 +39,7 @@ # All below convert to/from base ["g", _("gram"), _("grams"), "x * 1", "x * 1"], ["l", _("litre"), _("litres"), "x / 0.001", "x * 0.001"], + ["decal", _("decalitre"), _("decalitres"), "x / 0.0001", "x * 0.0001"], ["pt", _("pint US"), _("pints US"), "x / 0.002113383", "x * 0.002113383"], [ "ptimp", @@ -124,6 +126,62 @@ "x / 0.03519508", "x * 0.03519508", ], + [ + "dm3", + _("cubic decimetre"), + _("cubic decimetres"), + "x / 0.001", + "x * 0.001", + ], + [ + "mm3", + _("cubic millimetre"), + _("cubic millimetres"), + "x / 0.1000", + "x * 0.1000", + ], + [ + "cm3", + _("cubic centimetre"), + _("cubic centimetres"), + "x / 1", + "x * 1", + ], + [ + "m3", + _("cubic metre"), + _("cubic metres"), + "x / 0.000001", + "x * 0.000001", + ], + [ + "in3", + _("cubic inch"), + _("cubic inches"), + "x / 0.061024", + "x * 0.061024", + ], + [ + "ft3", + _("cubic feet"), + _("cubic feet"), + "x / 0.0000353147", + "x * 0.0000353147", + ], + [ + "buuk", + _("bushel UK"), + _("bushels UK"), + "x / 0.0000274961", + "x * 0.0000274961", + ], + [ + "buus", + _("bushel US"), + _("bushels US"), + "x / 0.0000283776", + "x * 0.0000283776", + ], ], "Area": [ # Base @@ -192,4 +250,82 @@ ["f", _("Farenheit"), _("Farenheit"), "(x - 32) / 1.8", "(x * 1.8) + 32"], ["k", _("Kelvin"), _("Kelvin"), "x - 273.15", "x + 273.15"], ], + "Speed": [ + # Base + ["km/h", _("kilometres per hour"), _("kilometres per hour"), "x * 1", "x * 1"], + [ + "m/s", + _("metres per second"), + _("metres per second"), + "x / 0.2777777778", + "x * 0.2777777778", + ], + [ + "mp/h", + _("miles per hour"), + _("miles per hour"), + "x / 0.6213711922", + "x * 0.6213711922", + ], + [ + "kt", + _("knot"), + _("knots"), + "x / 0.5399568035", + "x * 0.5399568035", + ], + ], + "Energy": [ + # Base + ["J", _("joule"), _("joules"), "x * 1", "x * 1"], + [ + "cal", + _("calorie"), + _("calories"), + "x / 0.2388459", + "x * 0.2388459", + ], + [ + "kcal", + _("kilocalorie"), + _("kilocalories"), + "x / 0.0002388459", + "x * 0.0002388459", + ], + [ + "kJ", + _("kilojoule"), + _("kilojoules"), + "x / 0.001", + "x * 0.001", + ], + [ + "MJ", + _("megajoule"), + _("megajoules"), + "x / 0.000001", + "x * 0.000001", + ], + [ + "Gj", + _("gigajoule"), + _("gigajoules"), + "x / 0.0000000010", + "x * 0.0000000010", + ], + [ + "kWh", + _("kilowatt hour"), + _("kilowatt hours"), + "x / 0.0000002778", + "x * 0.0000002778", + ], + [ + "BTU", + _("British thermal unit"), + _("British thermal units"), + "x / 0.0009478171", + "x * 0.0009478171", + ], + ], } diff --git a/plugin/utils.py b/plugin/utils.py deleted file mode 100644 index fb871ce..0000000 --- a/plugin/utils.py +++ /dev/null @@ -1,128 +0,0 @@ -import re -import plugin.units as gc_units -from plugin.extensions import _ - - -def get_hints_for_category(from_unit: str): - """Takes an input unit and returns a list of units it can be converted to - - :param from_short: unit abbreviation - :type amount: str - - :rtype: list - :return: A list of other unit abbreviations in the same category - """ - c = [] - category = "" - - # Find the category it's in - for u in gc_units.units: - for u2 in gc_units.units[u]: - if u2[0] == from_unit: - category = str(u) - for uu in gc_units.units[category]: - if uu[0] != from_unit: - c.append(uu[0]) - if category: - return c - else: - return ["no valid units"] - - -def get_all_units(short=False): - """Returns all available units as a list of lists by category - - :param short: if True only unit abbreviations are returned, default is False - :type amount: bool - - :rtype: list of lists - :return: A list of lists for each category in units. Index 0 of each internal list - is the category description - """ - - full_list = [] - for u in gc_units.units: - cat_list = [] - cat_list.append(u) - for u2 in gc_units.units[u]: - cat_list.append(u2[0] if short else f"{u2[1]} ({u2[0]})") - full_list.append(cat_list) - return full_list - - -def gen_convert(amount: float, from_unit: str, to_unit: str): - """Converts from one unit to another - - :param amount: amount of source unit to convert - :type amount: float - :param from_unit: abbreviation of unit to convert from - :type from_unit: str - :param to_unit: abbreviation of unit to convert to - :type to_unit: str - - :rtype: dict - :return: if to_unit and from_unit are valid returns a dictionary - { - "category":{category of units}, - "converted":{converted amount}, - "fromabbrev":{from unit abbreviation}, - "fromlong":{from unit long name}, - "fromplural":{from unit plural name}, - "toabbrev":{to unit abbreviation}, - "tolong":{to unit long name}, - "toplural":{to unit plural name}, - } - - else returns a dictionary with error status - {"Error": {error text}} - """ - conversions = {} - found_from = found_to = [] - if from_unit == to_unit: - conversions["Error"] = _("To and from unit is the same") - return conversions - for u in gc_units.units: - for u2 in gc_units.units[u]: - if u2[0] == from_unit: - found_from = u2 - if u2[0] == to_unit: - found_to = u2 - # If we haven't both in the same category, reset - if found_to and found_from: - found_category = u - break - else: - found_from = found_to = [] - if found_to and found_from: - base_unit_conversion = eval(found_from[3].replace("x", str(amount))) - final_conversion = eval(found_to[4].replace("x", str(base_unit_conversion))) - conversions["category"] = found_category - conversions["converted"] = final_conversion - conversions["fromabbrev"] = found_from[0] - conversions["fromlong"] = found_from[1] - conversions["fromplural"] = found_from[2] - conversions["toabbrev"] = found_to[0] - conversions["tolong"] = found_to[1] - conversions["toplural"] = found_to[2] - - else: - conversions["Error"] = _( - "Problem converting {} and {}".format(from_unit, to_unit) - ) - return conversions - - -def smart_precision(separator, amount, preferred=3): - str_amt = str(amount) - dec_places = str_amt[::-1].find(separator) - # whole number - if dec_places == -1: - return 0 - frac_part = str_amt[-dec_places::] - # fraction is just zeroes - if int(frac_part) == 0: - return 0 - fnz = re.search(r"[1-9]", frac_part).start() - if fnz < preferred: - return preferred - return fnz + 1 diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 123fc3e..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,2 +0,0 @@ -click -babel \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 26d477d..e251760 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ -flowlauncher -python-dotenv -typing \ No newline at end of file +flox-lib==0.19.6 +python-dotenv==0.20.0 diff --git a/test.py b/test.py deleted file mode 100644 index 5d8de95..0000000 --- a/test.py +++ /dev/null @@ -1,8 +0,0 @@ -# -*- coding: utf-8 -*- - - -from plugin import Main - -if __name__ == "__main__": - r = Main().query("") - print(r) \ No newline at end of file