nl.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-FileCopyrightText: Adam Evyčędo
  2. //
  3. // SPDX-License-Identifier: AGPL-3.0-or-later
  4. package transformers
  5. import (
  6. "golang.org/x/text/transform"
  7. )
  8. //nolint:gochecknoglobals
  9. var TransformerNL transform.Transformer = ContextualLatiniser{
  10. Replace: func(previous, r rune) []rune {
  11. switch r {
  12. case 'á':
  13. return []rune{'a'}
  14. case 'Á':
  15. return []rune{'A'}
  16. case 'ij':
  17. return []rune{'i', 'j'}
  18. case 'IJ':
  19. return []rune{'I', 'J'}
  20. case 'ä':
  21. if previous != ZWJ {
  22. return []rune{'a'}
  23. }
  24. return []rune{r}
  25. case 'Ä':
  26. if previous != ZWJ {
  27. return []rune{'A'}
  28. }
  29. return []rune{r}
  30. case 'ë':
  31. return []rune{'e'}
  32. case 'Ë':
  33. return []rune{'E'}
  34. case 'ï':
  35. return []rune{'i'}
  36. case 'Ï':
  37. return []rune{r}
  38. case 'ö':
  39. if previous != ZWJ {
  40. return []rune{'o'}
  41. }
  42. return []rune{r}
  43. case 'Ö':
  44. if previous != ZWJ {
  45. return []rune{'O'}
  46. }
  47. return []rune{r}
  48. case 'ü':
  49. if previous != ZWJ {
  50. return []rune{'u'}
  51. }
  52. return []rune{r}
  53. case 'Ü':
  54. if previous != ZWJ {
  55. return []rune{'U'}
  56. }
  57. return []rune{r}
  58. default:
  59. return []rune{r}
  60. }
  61. },
  62. }