-- lx format
local format = require("core.format")
local quotes = require("core.text.quotes")

format.register({
	name = "Gettext Translation",
	shortname = "PO",
	author = "liqube",

	extensions = { "po", "pot" },
	comment = "#",

	patterns = {
		-- Obsolete entry line
		{ pattern = "#~.-\n", type = "comment", line_start = true },
		{ pattern = "#~.+", type = "comment", line_start = true },

		-- Previous untranslated entry line
		{ pattern = "#|.-\n", type = "comment", line_start = true },
		{ pattern = "#|.+", type = "comment", line_start = true },

		-- Source reference comment
		{
			pattern = "(#:)(%s*)(.-)\n",
			type = { "comment", "normal", "meta" },
			line_start = true,
		},

		-- Source reference comment at end of file
		{
			pattern = "(#:)(%s*)(.+)",
			type = { "comment", "normal", "meta" },
			line_start = true,
		},

		-- Flag comment
		{
			pattern = "(#,)(%s*)(.-)\n",
			type = { "comment", "normal", "keyword2" },
			line_start = true,
		},

		-- Flag comment at end of file
		{
			pattern = "(#,)(%s*)(.+)",
			type = { "comment", "normal", "keyword2" },
			line_start = true,
		},

		-- Extracted comment
		{ pattern = "#%..-\n", type = "comment", line_start = true },
		{ pattern = "#%.+", type = "comment", line_start = true },

		-- Plain translator comment
		{ pattern = "#.-\n", type = "comment", line_start = true },
		{ pattern = "#.+", type = "comment", line_start = true },

		-- Message context
		{
			pattern = "(msgctxt)(%s+)",
			type = { "keyword", "normal" },
			line_start = true,
		},

		-- Plural source message
		{
			pattern = "(msgid_plural)(%s+)",
			type = { "keyword", "normal" },
			line_start = true,
		},

		-- Source message
		{
			pattern = "(msgid)(%s+)",
			type = { "keyword", "normal" },
			line_start = true,
		},

		-- Indexed plural translation
		{
			pattern = "(msgstr)(%[)(%d+)(%])(%s+)",
			type = { "keyword", "operator", "number", "operator", "normal" },
			line_start = true,
		},

		-- Translation
		{
			pattern = "(msgstr)(%s+)",
			type = { "keyword", "normal" },
			line_start = true,
		},

		-- Quoted string
		{ pattern = { '"', '"', "\\" }, type = "string" },
	},

	outline_patterns = {
		-- Message context
		{ pattern = "%s*msgctxt%s+\".-\"", line_start = true },

		-- Source message
		{ pattern = "%s*msgid%s+\".-\"", line_start = true },

		-- Plural source message
		{ pattern = "%s*msgid_plural%s+\".-\"", line_start = true },
	},

	quotes = {
		primary = "double",
		profiles = {
			double = quotes.profile.c_style_double(),
		},
	},

	symbols = {
		-- Entry keywords
		["msgctxt"] = "keyword",
		["msgid"] = "keyword",
		["msgid_plural"] = "keyword",
		["msgstr"] = "keyword",

		-- Common flags
		["fuzzy"] = "keyword2",
		["c-format"] = "keyword2",
		["no-c-format"] = "keyword2",
		["python-format"] = "keyword2",
		["no-python-format"] = "keyword2",
		["javascript-format"] = "keyword2",
		["no-javascript-format"] = "keyword2",
		["php-format"] = "keyword2",
		["no-php-format"] = "keyword2",
		["perl-format"] = "keyword2",
		["no-perl-format"] = "keyword2",
		["java-format"] = "keyword2",
		["no-java-format"] = "keyword2",
		["objc-format"] = "keyword2",
		["no-objc-format"] = "keyword2",
		["qt-format"] = "keyword2",
		["no-qt-format"] = "keyword2",
		["kde-format"] = "keyword2",
		["no-kde-format"] = "keyword2",
	},
})
