Commit graph

193 commits

Author SHA1 Message Date
46f419ff14 Update README 2024-07-28 11:12:48 -07:00
6067ad4d7a Rename package 2024-07-21 23:33:58 -07:00
7911f2a8a9 Remove usage of gob 2024-07-21 23:30:26 -07:00
7af07d2ba5 Add flag -no-locations
This flag controls whether translation location information is written.
2024-07-21 23:27:42 -07:00
f8b774e33a Update README 2024-07-21 23:18:00 -07:00
Leonel Quinteros
b119ef1075
Address Domain Set and SetN bug. Fixes #99 2024-06-05 11:04:20 -03:00
Leonel Quinteros
c7c2135ff2
Merge pull request #85 from m-horky/multilang
Add support for multiple languages
2024-04-09 10:37:50 -03:00
Matyas Horky
8979030aff Rename 'storage' to 'locale'
As the package matured, it makes sense to use unified names everywhere.
Since the config holds Locale objects, the variable is called 'locales'.

This patch finishes the work and updates the 'loadStorage' function
to be called 'localLocales' with argument 'rebuildCache' instead of
'force'.
2024-01-09 13:27:49 +01:00
Matyas Horky
f7ff9bf787 Fix a typo in documentation for SetLibrary 2023-12-19 10:34:08 +01:00
Matyas Horky
4ec5f399f4 Add support for multiple languages
gettext supports supplying multiple languages using the colon character
$ LANGUAGE=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.

8/ GetLocales/GetStorage, SetLocales/SetStorage
 - Following recent changes, created public functions to manipulate with
   global configuration's locales. The *Storage functions are renamed
   in later commit to reduce the amount of changes in one commit.
2023-12-19 10:34:08 +01:00
Leonel Quinteros
12a99145a3
Merge pull request #87 from der-lyse/fix-typo
Fix typo in documentation
2023-10-03 09:22:55 -03:00
Lysander Trischler
d1606942e6 Fix typo in documentation
There is no `NewPoTranslator` function, it's called `NewPo` instead.
2023-09-26 10:52:49 +02:00
Leonel Quinteros
6f739b683b
Merge pull request #86 from der-lyse/master
Remove unused dependency
2023-09-25 11:49:41 -03:00
Lysander Trischler
2f11fcd5f2 Remove unused dependency
While figuring out what both dependencies in gotext are used for, I
quickly noticed that one is actually useless at the moment. The `tag`
field is only set but never used, so it can be dropped. It was
introduced three years ago in bb276626f3
and was even not used back then. I didn't check the history any further,
though. Removing the private field allows getting rid of a third-party
dependency entirely.
2023-09-24 22:28:12 +02:00
Leonel Quinteros
37f474cfb0
Merge pull request #84 from leonelquinteros/revert-73-multilang
Revert "Add support for multiple languages"
2023-08-29 13:20:19 -03:00
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