Erik Montnemery
d31124d5d4
Avoid creating unneeded Context and Event objects when firing events ( #113798 )
...
* Avoid creating unneeded Context and Event objects when firing events
* Add test
---------
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-20 09:40:06 +01:00
Jan Bouwhuis
554aefed42
Generate HomeAssistantError message from English translations ( #113305 )
...
* Fetch exception message from translation cache
* Improve tests
* Return translation key without path, cleanup
* Fetch translations when string variant is requested
* Move import
* revert changes ConfigValidationError
* mypy
* Remove _str__ method instead
* Type _message for mqtt template exception classes
* Revert changes made to test_config.py
* Undo changes TemplateError
* Follow up comments and test coverage
2024-03-16 22:56:48 +01:00
J. Nick Koston
08416974c9
Avoid trying to load translations for integrations that have none ( #112683 )
2024-03-08 14:21:44 -10:00
Marc Mueller
19ab3d6daf
Add empty line after module docstring [helpers + other] ( #112707 )
2024-03-08 10:36:11 -05:00
J. Nick Koston
982c8f8f4a
Fix incorrect scope on checking files to load in translations ( #112457 )
...
discovered in https://github.com/home-assistant/core/pull/112295#discussion_r1513505710
We only checked if the last language had files to load
instead of all of them. The checks for each language
are the same because the only reason we would skip
a language is a missing/broken integration or the integration
is a single file. Both of these loop conditions are always
the same reguardless of the language so the check worked
2024-03-05 23:46:24 -05:00
J. Nick Koston
fbabbc8f92
Limit legacy state translations to custom components ( #112295 )
...
* Limit legacy state translations to custom components
We were trying to load **thousands** of `*.light.json`, `*.switch.json` files at run time that did not exist.
There have been replaced with entity translations: https://github.com/home-assistant/developers.home-assistant/pull/1557 https://github.com/home-assistant/core/pull/82701
https://github.com/home-assistant/core/pull/112023 will completely remove them, but
for now we will only load them for custom components to reduce the number
of files having to be examined
* reduce
* reduce
* reduce
* reduce
* comment
* coverage
* try to remove empty dict in loaded_translations fallback when missing
2024-03-05 17:27:45 -05:00
J. Nick Koston
dd80157dc7
Load translations at setup time if they were not loaded at bootstrap ( #110921 )
2024-02-24 11:31:25 -10:00
J. Nick Koston
9ce1ec414e
Reduce overhead to load multiple languages in translations ( #111028 )
...
* Reduce overhead to load multiple languages in translations
Instead of loading in a task, we now group everything
to be loaded into a single executor job
* fixes
* fixes
* fixes
* fixes
* fixes
* update tests
* add missing coverage (was existing)
2024-02-20 21:52:28 -05:00
J. Nick Koston
16653ff5d0
Group loading of translations for integrations to reduce executor jobs at startup ( #110674 )
2024-02-17 21:08:55 -06:00
J. Nick Koston
9bc130c131
Ensure translations for other integrations can be loaded if one integration fails ( #110748 )
...
* load failure
* merge
2024-02-17 21:01:36 -05:00
J. Nick Koston
2cb0249f0a
Add filter to translation event listeners to avoid creating tasks ( #110732 )
2024-02-16 12:13:23 -06:00
Piotr Machowski
a2f4e99994
Add state_translated function to jinja templates ( #96906 )
...
* Add state_translated jinja function
* Add tests for load_state_translations_to_cache and get_cached_translations
* Cleanup state_translated template
* Add tests for state_translated jinja function
* Apply black formatting
* Improve code quality
* Apply suggestions from code review
Co-authored-by: Erik Montnemery <erik@montnemery.com>
* Apply suggestions from code review
* Prevent invalid components from loading translations
* Refactor loading translations to cache
* Adjust code issues
* Update homeassistant/helpers/translation.py
Co-authored-by: Erik Montnemery <erik@montnemery.com>
* Refactor listeners that trigger translation loading
* Apply suggestions from code review
Co-authored-by: Erik Montnemery <erik@montnemery.com>
* Apply suggestions from code review
* Adjust invalid function calls, fix code styling
* Adjust code quality
* Extract async_translate_state function
* Apply suggestions from code review
Co-authored-by: Erik Montnemery <erik@montnemery.com>
* Apply suggestions from code review
* Fix tests
* Fix tests
---------
Co-authored-by: Piotr Machowski <PiotrMachowski@users.noreply.github.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-10 10:47:56 +01:00
Michael
d049928be7
Log error and continue on parsing issues of translated strings ( #110046 )
2024-02-09 08:35:12 +01:00
J. Nick Koston
f883f721c8
Avoid copying translations for single components ( #108645 )
2024-01-24 19:52:34 +01:00
J. Nick Koston
4a34cd25b2
Reduce lock contention when all translations are already cached ( #108634 )
2024-01-21 22:29:03 -10:00
Franck Nijhof
01372024f5
Add icon translations support ( #103294 )
...
Co-authored-by: Robert Resch <robert@resch.dev>
Co-authored-by: Paul Bottein <paul.bottein@gmail.com>
2024-01-19 16:56:56 +01:00
J. Nick Koston
368feec712
Refactor translations to reduce dict lookups ( #107425 )
...
* Refactor translations to reduce dict lookups
All of our cache lookups used:
`cache[language][O(component)][category]`
The cache was designed as
`cache[language][component][category][flatted_key]`
The lookups are now
`cache[language][category][O(component)]`
The cache is now stored as
`cache[language][category][component][flatted_key]`
This allows the catch fetch to avoid looking up
the category each loop
* already a set, and we do not mutate
2024-01-07 22:29:27 -05:00
Michael
eb01998395
Add support for placeholders in entity name translations ( #104453 )
...
* add placeholder support to entity name translation
* add negativ tests
* make property also available via description
* fix doc string in translation_placeholders()
* fix detection of placeholder
* validate placeholders for localized strings
* add test
* Cache translation_placeholders property
* Make translation_placeholders uncondotionally return dict
* Fall back to unsubstituted name in case of mismatch
* Only replace failing translations with English
* Update snapshots
* Blow up on non stable releases
* Fix test
* Update entity.py
---------
Co-authored-by: Erik <erik@montnemery.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-01-03 17:34:47 +01:00
Ville Skyttä
24b1e01d71
Update Ruff to 0.1.8, avoid linter/formatter conflicts ( #106080 )
...
* Disable Ruff rules that may conflict with the formatter
* Upgrade Ruff to 0.1.8
- https://github.com/astral-sh/ruff/releases/tag/v0.1.7
- https://github.com/astral-sh/ruff/releases/tag/v0.1.8
* Format with Ruff 0.1.8
2023-12-20 23:55:09 +01:00
Erik Montnemery
84e74e4c74
Reverse component path ( #104087 )
...
* Reverse component path
* Update translations helper
* Fix
* Revert incorrect change of PLATFORM_FORMAT
* Fix use of PLATFORM_FORMAT in tts
* Fix ios
2023-12-05 08:43:58 +01:00
J. Nick Koston
3b8d99dcd8
Add __slots__ to translation cache ( #100069 )
2023-09-10 20:46:55 +02:00
Franck Nijhof
f054de0ad5
Add support for service translations ( #95984 )
2023-07-11 15:52:12 +02:00
Franck Nijhof
f32b7859b8
Restructure translations for entity components ( #89702 )
2023-03-16 12:16:08 +01:00
J. Nick Koston
8806c3dd20
Speed up loading non-english language translations ( #88553 )
...
Speed up loading non-english languages
We called async_get_integrations in each gathered task
instead of once for both languages we were loading
2023-02-21 21:18:33 -05:00
Franck Nijhof
06a35fb7db
Code styling tweaks to core helpers ( #85441 )
2023-01-08 13:44:09 -10:00
J. Nick Koston
194adcde9c
Drop ChainMap in translation cache ( #85260 )
2023-01-06 11:52:18 -10:00
Franck Nijhof
d4f69a3652
String formatting and max line length - Part 7 ( #84532 )
...
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2022-12-27 11:18:56 +01:00
Aarni Koskela
8038485ca4
Use partition instead of split where possible in core ( #81806 )
2022-11-15 21:45:48 +01:00
J. Nick Koston
61cc9f5288
Consolidate executor jobs when loading integration manifests ( #75176 )
2022-07-14 13:06:08 -07:00
J. Nick Koston
a614ddca28
Support requesting translations for multiple integrations in a single request ( #71979 )
2022-05-17 01:23:11 -05:00
Marc Mueller
3b3e12aaa2
Fix `translation` typing ( #66516 )
2022-02-14 09:23:12 -08:00
Marc Mueller
240c9979c7
Move `disallow-any-generics` to mypy.ini ( #63917 )
2022-01-11 13:33:25 -08:00
Ville Skyttä
59809503d1
Various type hint related improvements ( #54971 )
...
* Avoid some implicit generic Anys
* Fix hassio discovery view type hints
* Fix http view result type in assert message
2021-08-21 13:58:49 +02:00
Ville Skyttä
470f2dd73f
Upgrade pyupgrade to 2.21.2, apply its changes ( #52987 )
2021-07-19 10:46:09 +02:00
Franck Nijhof
38d14702fa
Remove HomeAssistantType alias from helpers ( #48400 )
2021-03-27 12:55:24 +01:00
Marc Mueller
6fb2e63e49
Update typing 02 ( #48014 )
2021-03-17 18:34:19 +01:00
J. Nick Koston
94bf55e29b
Limit concurrency of async_get_integration to avoid creating extra threads ( #43085 )
...
* Limit concurrency of async_get_integration to avoid creating extra threads
Since async_get_integration is waiting on the disk most of the time
it would end up creating many new threads because the disk could
not deliver the data in time.
* pylint
2020-11-10 21:34:54 -10:00
J. Nick Koston
c7f35b20fb
Make all translations cacheable ( #42892 )
2020-11-09 22:36:45 +01:00
J. Nick Koston
5ca4b4cd0f
Set the translations cache under the lock ( #42470 )
2020-10-27 22:02:38 +01:00
Franck Nijhof
1c2ebdf307
Upgrade black to 20.8b1 ( #39287 )
2020-08-27 13:56:20 +02:00
Joakim Sørensen
835f433cf7
Remove loading of legacy translations ( #37021 )
2020-06-23 10:58:11 +02:00
Paulus Schoutsen
b3201523aa
Fix translation merging for custom components without translations ( #35032 )
2020-05-01 11:34:09 -07:00
Paulus Schoutsen
e9ff1940d6
Translation fixes and tweaks ( #34489 )
...
Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>
2020-04-21 17:57:21 -07:00
Joakim Sørensen
730a257f3c
Rename translations dir for integrations ( #34494 )
2020-04-21 16:11:05 -07:00
Paulus Schoutsen
4720a7a891
Add foundation for state translations ( #34443 )
2020-04-19 20:35:49 -07:00
Paulus Schoutsen
d10f5a48d4
Fix translations merging ( #34417 )
...
Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>
2020-04-19 12:37:44 -07:00
Paulus Schoutsen
98f1548f2d
Allow fetching translations by categories ( #34329 )
2020-04-18 17:13:13 -07:00
Paulus Schoutsen
94a3cec4bf
Take integration title from manifest if not translated ( #34283 )
2020-04-16 08:38:54 -07:00
Ville Skyttä
fa4fa30461
Various string cleanups ( #30435 )
...
* Remove some unnecessary string concatenations
* Replace some simple str.formats with f-strings
* Replace some string concatenations with f-strings
2020-01-03 14:47:06 +01:00
Bas Nijholt
67c56c860d
Sort imports according to PEP8 for 'homeassistant' folder ( #29789 )
...
Components are already done
2019-12-09 16:42:10 +01:00