Commit graph

178 commits

Author SHA1 Message Date
Leonel Quinteros
4c923532a0
Revert "Add support for multiple languages" 2023-08-29 13:20:03 -03:00
Leonel Quinteros
dfd3da1f54
Merge pull request #73 from m-horky/multilang
Add support for multiple languages
2023-08-29 13:11:33 -03:00
Leonel Quinteros
5680cf25e7
Merge pull request #79 from diamondburned/master
Fix io/fs File leak
2023-08-29 12:43:10 -03:00
Leonel Quinteros
d32dc82045
Merge pull request #83 from didrocks/fix-location-order
Order locations in ascii order
2023-08-29 12:40:39 -03:00
Leonel Quinteros
b2e50035bf
Merge pull request #82 from didrocks/fix-multiline-export
Fix multiline export
2023-08-29 12:38:36 -03:00
Didier Roche
bc62da24a3
Order locations in ascii order
As in the pkg-tree implementation, the walking of different dependencies
are not determinated, this means that we may have references swapping
between consecutive runs. Ensure we always order them the same way now.
2023-07-26 16:56:09 +02:00
Didier Roche
4d8518bd51
Adapt multi-line test
This is the use case the more demanding: multi-line not finishing by
EOL.
Adapt the expect case for it.
2023-07-26 13:16:54 +02:00
Didier Roche
67c19dca01
Apply same multi-line logic when marhsalling to text
Ensure we follow the same rule when exporting to text format.
This allows multi-line exports following the convention of single line,
EOL at the end of the string and more.
2023-07-26 13:12:27 +02:00
Didier Roche
b65bc5e2b1
Add more test cases and refresh tests for pot generation
Ensure that the .po reflects latest translations (some were missing)
Add more translations to reflect the new fixed use cases.
2023-07-26 13:05:46 +02:00
Didier Roche
7f9fe4dccc
Fix multi-line and backquotes string pot generation
The extraction of gettext entry does not translate properly multiline nor
backquotes:
* Multilines are printed as is, instead of follow the gettext spec:
  https://www.gnu.org/software/gettext/manual/html_node/Normalizing.html
* Strings with backquotes as printed as “msgid `this is my string`”,
* Multilines strings with backquotes are formatted as multi-lines to, without
  closing quotes on each lines.

The loading is correct though, this only impact the generation file.
Those generated files are thus then invalid and can’t be compile to mo file.
2023-07-26 13:05:46 +02:00
Leonel Quinteros
1f7d156c36
Merge pull request #80 from didrocks/allow-setting-global-storage
Allow setting global storage
2023-07-18 11:00:14 -03:00
Didier Roche
6638bd22d1
Tests for setting and getting locale as global configuration.
Ensure we override and set expected properties on the default config
object.
2023-07-18 15:39:23 +02:00
Didier Roche
0574165f92
Allow to Set and Get global locale storage
By setting globalConfig.storage object, it's up to the loading wrapper to set
Locale.Domains map to desired manually loaded Translators like embedding po as
[]bytes or so, using dedicated files…
Then, the project can use gotext.Get() or any root level methods
transparently.

This is very useful if you want to test your code from your own repo (using
embedded po files if you detect the root of your projects), while still being
able to build your project and deploy to an installation, which will load from
/usr/share/…

Fixes: #52.
2023-07-18 15:39:20 +02:00
diamondburned
4e20082713
Fix io/fs File leak 2023-05-29 15:56:15 -07:00
Matyas Horky
9a5081df4b Fix a typo in documentation for SetLibrary 2023-05-15 13:00:33 +02:00
Matyas Horky
831b071cb6 Handle special locale 'C'
Specifying C disables all further localization.
2023-05-15 13:00:33 +02:00
Matyas Horky
7125c7d841 Add support for multiple languages
gettext supports supplying multiple languages using the colon character
$ LC_ALL=pt_BR:pt_PT:en_US foo bar
which are used as fallback: when a translation for the first one is not
available, the second language is used. If no language contains
a translation for the string `msgid` is returned.

This patch adds this support into gotext.

1/ config struct
 - 'language' was renamed to 'languages' and is a slice of strings
 - 'storage' was renamed to 'locales' and is a slice of Locale pointers

2/ loadStorage()
 - all loaded languages are iterated over

3/ GetLanguages()
 - new function returns the languages from the config
 - GetLanguage() uses the first element of it, keeping the compatibility

4/ SetLanguage(), Configure()
 - the language string is split at colon and iterated over

5/ Get*()
 - languages are iterated and the first translation for given string is
   returned

6/ IsTranslated*()
 - new optional parameter (langs) has been added

7/ Locale.GetActualLanguage()
 - it checks the filesystem and determines what the actual language code
   is: for 'cs_CZ', just 'cs' may be returned, depending on the actual
   name of the .mo/.po file.
2023-05-15 13:00:33 +02:00
Leonel Quinteros
db315c3450
Merge pull request #77 from taozhou-glean/tao-add-get-language
feat: Add language getter for Locale
2023-05-09 15:50:24 -03:00
Tao Zhou
5b7d0bd80c
feat: Add language getter for Locale 2023-05-07 16:23:20 -07:00
Leonel Quinteros
4829902c8b
Merge pull request #69 from m-horky/is-translated
Runtime translation detection
2023-04-13 08:53:40 -03:00
Matyas Horky
3a68971094 Detect translations in high-level structs
This patch adds .IsTranslated(), .IsTranslatedN() and related functions
to following objects:
- Po
- Mo
- locale
- gotext
and it creates helper interfaces in introspector.go.

This makes it possible to detect whether a string is translatable or not
during runtime.

Resolves #42
2023-04-12 17:15:46 +02:00
Matyas Horky
8941f8bb1c Detect translations in low-level structs
This patch adds .IsTranslated(), .IsTranslatedN() and related functions
to following objects:
- Translation
- Domain

This makes it possible to detect whether a string is translatable or not
during runtime.
2023-04-04 18:12:48 +02:00
Matyas Horky
4ce6b50c65 Rename contexts to contextTranslations
This will keep the names consistent across the three members
2023-04-04 17:12:29 +02:00
Leonel Quinteros
71a59c05b2
Merge pull request #68 from kobergj/AddFSToLocale
Allow locale to use a `fs.FS`
2023-03-17 10:09:43 -03:00
jkoberg
8ebc12be37 test fs alongside os implementation
Signed-off-by: jkoberg <jkoberg@owncloud.com>
2023-03-17 11:29:18 +01:00
jkoberg
9d5a301452 allow locale to work with a fs.FS
Signed-off-by: jkoberg <jkoberg@owncloud.com>
2023-03-16 10:53:22 +01:00
Leonel Quinteros
6f9bcaa969
Merge pull request #67 from leonelquinteros/dependabot/go_modules/golang.org/x/text-0.3.8
Bump golang.org/x/text from 0.3.7 to 0.3.8
2023-02-23 09:18:08 -03:00
dependabot[bot]
2c591ae0d8
Bump golang.org/x/text from 0.3.7 to 0.3.8
Bumps [golang.org/x/text](https://github.com/golang/text) from 0.3.7 to 0.3.8.
- [Release notes](https://github.com/golang/text/releases)
- [Commits](https://github.com/golang/text/compare/v0.3.7...v0.3.8)

---
updated-dependencies:
- dependency-name: golang.org/x/text
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-23 09:29:48 +00:00
Leonel Quinteros
531e674405
Update build.yml 2022-12-20 18:29:35 -03:00
Leonel Quinteros
6998e37f95
Merge pull request #65 from akissa/master
Minor documentation fixes
2022-06-08 16:58:45 -03:00
Andrew Colin Kissa
1a80e8e8a0
Fix minor typos
Fix comments to ensure correct docs generated
2022-06-08 13:54:15 +02:00
Andrew Colin Kissa
e5a058f289
Fix incorrect example 2022-06-08 13:49:57 +02:00
Leonel Quinteros
59de4ff80c
Update build.yml
Bump Go build version to 1.18
2022-04-25 11:15:23 -03:00
Leonel Quinteros
c7fb758575
Merge pull request #63 from Vorlif/deps-update
Dependencies update
2022-04-25 11:13:56 -03:00
Leonel Quinteros
6e87618db7
Merge pull request #64 from Vorlif/plurals-license
Changing the copyright header for plurals package
2022-04-25 11:10:34 -03:00
Florian Vogt
fe1eafc9a2
Proposal 2022-04-24 23:09:15 +02:00
Florian Vogt
572e8fce2e
Remove dep from README.md 2022-04-24 17:39:39 +02:00
Florian Vogt
715a8d7d35
Dependencies update 2022-04-24 17:38:33 +02:00
Leonel Quinteros
4f17e07cb4
Merge pull request #61 from felixvd/fix-po-export
Format quotation marks and newlines for PO export
2022-03-31 12:11:18 -03:00
Felix von Drigalski
38cf034b07
Fix test 2022-03-31 23:34:21 +09:00
Felix von Drigalski
24bcff57f7 Format quotation marks, newlines for PO export 2022-03-31 13:55:00 +09:00
Leonel Quinteros
01cdb5049e
Update README.md 2021-12-21 10:53:53 -03:00
Leonel Quinteros
d5f5ca40c5
Update README 2021-12-21 10:51:58 -03:00
Leonel Quinteros
5e27e8b5e0
Merge pull request #55 from m90/patch-1
Fix arg type in docstring for (*Po).Parse
2021-09-26 11:00:56 -03:00
Frederik Ring
771e397901
Fix arg type in docstring for (*Po).Parse
The Godoc string currently does not match the function's signature.
2021-09-19 11:46:13 +02:00
Leonel Quinteros
7d0f5cde4d
Merge pull request #54 from itimky/xgotext-performance
-pkg-tree flag for performance
2021-09-16 17:12:11 -03:00
Tim Green
d5f757e198 load package tree once and traverse 2021-09-16 19:02:06 +03:00
Leonel Quinteros
1b8a993ae4
Merge pull request #47 from razor-1/getall
Add GetTranslations methods to Locale and Domain
2020-10-29 10:51:54 -03:00
Jon Snyder
a1f059fb62 optimize: make the domain map the correct size when initialized 2020-10-28 16:11:06 -07:00
Jon Snyder
69291164ca add GetTranslations methods to Locale and Domain to allow access to all translations 2020-10-28 16:06:55 -07:00