Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app.worktrack.feature.leave

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import app.worktrack.core.model.LeaveType

/** Only the untouched Dari names signup seeds are translated; a company's own name stays as typed. */
internal fun builtInNameRes(type: LeaveType): Int? = when {
type.code == "ANNUAL" && type.name == "رخصتی سالانه" -> R.string.leave_type_annual
type.code == "SICK" && type.name == "رخصتی مریضی" -> R.string.leave_type_sick
else -> null
}

@Composable
internal fun LeaveType.displayName(): String = builtInNameRes(this)?.let { stringResource(it) } ?: name
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import app.worktrack.core.designsystem.l10n.formatShamsiDate
import app.worktrack.core.designsystem.l10n.localizedDigits
import app.worktrack.core.designsystem.l10n.localizedMessage
import app.worktrack.feature.leave.R
import app.worktrack.feature.leave.displayName
import java.time.Instant
import java.time.LocalDate
import java.time.ZoneOffset
Expand Down Expand Up @@ -72,7 +73,7 @@ fun ApplyLeaveRoute(
) { padding ->
ApplyLeaveScreen(
state = state,
typeNames = types.associate { it.id to it.name },
typeNames = types.associate { it.id to it.displayName() },
onTypeSelect = viewModel::onTypeSelect,
onStartDate = viewModel::onStartDate,
onEndDate = viewModel::onEndDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import app.worktrack.core.model.LeaveStatus
import app.worktrack.core.model.LeaveType
import app.worktrack.core.model.SyncStatus
import app.worktrack.feature.leave.R
import app.worktrack.feature.leave.displayName

@Composable
fun LeaveOverviewRoute(
Expand Down Expand Up @@ -183,7 +184,7 @@ private fun BalanceRow(
color = MaterialTheme.colorScheme.primary,
)
Text(
text = type?.name ?: stringResource(R.string.leave_generic_type),
text = type?.displayName() ?: stringResource(R.string.leave_generic_type),
style = MaterialTheme.typography.labelMedium,
)
if (balance.pendingDays > 0) {
Expand Down Expand Up @@ -220,7 +221,7 @@ private fun RequestCard(
Column(Modifier.weight(1f)) {
type?.let {
ColorDotChip(
text = it.name,
text = it.displayName(),
dotColor = parseHexColor(it.colorHex),
)
}
Expand Down
2 changes: 2 additions & 0 deletions feature/leave/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@
<string name="leave_reject_reason">Reason</string>
<string name="leave_msg_approved">Request approved</string>
<string name="leave_msg_rejected">Request rejected</string>
<string name="leave_type_annual">Annual leave</string>
<string name="leave_type_sick">Sick leave</string>
</resources>
2 changes: 2 additions & 0 deletions feature/leave/src/main/res/values-ps/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@
<string name="leave_reject_reason">دلیل</string>
<string name="leave_msg_approved">غوښتنه تایید شوه</string>
<string name="leave_msg_rejected">غوښتنه رد شوه</string>
<string name="leave_type_annual">کلنۍ رخصتي</string>
<string name="leave_type_sick">د ناروغۍ رخصتي</string>
</resources>
2 changes: 2 additions & 0 deletions feature/leave/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@
<string name="leave_reject_reason">دلیل</string>
<string name="leave_msg_approved">درخواست تایید شد</string>
<string name="leave_msg_rejected">درخواست رد شد</string>
<string name="leave_type_annual">رخصتی سالانه</string>
<string name="leave_type_sick">رخصتی مریضی</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package app.worktrack.feature.leave

import app.worktrack.core.model.LeaveType
import java.time.Instant
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test

class LeaveTypeNamesTest {

private fun type(code: String, name: String) = LeaveType(
id = code.lowercase(), companyId = "c1", name = name, code = code, colorHex = "#000000",
isPaid = true, requiresAttachment = false, active = true, updatedAt = Instant.EPOCH,
)

@Test
fun builtInTypesWithTheSeededNameAreTranslated() {
assertEquals(R.string.leave_type_annual, builtInNameRes(type("ANNUAL", "رخصتی سالانه")))
assertEquals(R.string.leave_type_sick, builtInNameRes(type("SICK", "رخصتی مریضی")))
}

@Test
fun aNameTheCompanyTypedIsKept() {
assertNull(builtInNameRes(type("ANNUAL", "رخصتی تفریحی")))
assertNull(builtInNameRes(type("HAJJ", "رخصتی حج")))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package app.worktrack.feature.payslips

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import app.worktrack.core.model.PayslipLine

/** Payroll names these three lines in Dari itself; company components keep their own names. */
internal fun builtInNameRes(line: PayslipLine): Int? = when (line.componentCode) {
"BASIC" -> R.string.pay_basic
"LOP" -> R.string.pay_absence
"TAX" -> R.string.pay_income_tax
else -> null
}

@Composable
internal fun PayslipLine.displayName(): String = builtInNameRes(this)?.let { stringResource(it) } ?: componentName
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import app.worktrack.core.designsystem.l10n.localizedDigits
import app.worktrack.core.model.PayComponentType
import app.worktrack.core.model.Payslip
import app.worktrack.feature.payslips.R
import app.worktrack.feature.payslips.displayName

@Composable
fun PayslipDetailRoute(
Expand Down Expand Up @@ -99,11 +100,11 @@ private fun PayslipDetail(payslip: Payslip, modifier: Modifier = Modifier) {

if (earnings.isNotEmpty()) {
SectionHeader(stringResource(R.string.pay_earnings))
LinesCard(lines = earnings.map { it.componentName to it.amount }, currency = payslip.currency)
LinesCard(lines = earnings.map { it.displayName() to it.amount }, currency = payslip.currency)
}
if (deductions.isNotEmpty()) {
SectionHeader(stringResource(R.string.pay_deductions))
LinesCard(lines = deductions.map { it.componentName to it.amount }, currency = payslip.currency)
LinesCard(lines = deductions.map { it.displayName() to it.amount }, currency = payslip.currency)
}

SectionHeader(stringResource(R.string.pay_attendance_summary))
Expand Down
3 changes: 3 additions & 0 deletions feature/payslips/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
<string name="pay_lop_label">Loss-of-pay days</string>
<string name="pay_all_months">All months</string>
<string name="pay_no_payslips_month_title">No payslip for %1$s</string>
<string name="pay_basic">Basic salary</string>
<string name="pay_absence">Absence deduction</string>
<string name="pay_income_tax">Income tax</string>
</resources>
3 changes: 3 additions & 0 deletions feature/payslips/src/main/res/values-ps/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
<string name="pay_lop_label">د معاش کسر ورځې</string>
<string name="pay_all_months">ټولې میاشتې</string>
<string name="pay_no_payslips_month_title">د %1$s لپاره د معاش فیش نشته</string>
<string name="pay_basic">اساسي معاش</string>
<string name="pay_absence">د غیرحاضرۍ کسر</string>
<string name="pay_income_tax">د معاش مالیه</string>
</resources>
3 changes: 3 additions & 0 deletions feature/payslips/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
<string name="pay_lop_label">روزهای کسر معاش</string>
<string name="pay_all_months">همه ماه‌ها</string>
<string name="pay_no_payslips_month_title">فیش معاشی برای %1$s نیست</string>
<string name="pay_basic">معاش اساسی</string>
<string name="pay_absence">کسر غیرحاضری</string>
<string name="pay_income_tax">مالیهٔ معاش</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package app.worktrack.feature.payslips

import app.worktrack.core.model.PayComponentType
import app.worktrack.core.model.PayslipLine
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test

class PayslipLineNamesTest {

private fun line(code: String, name: String) = PayslipLine(code, name, PayComponentType.EARNING, 1.0)

@Test
fun payrollWrittenLinesAreTranslated() {
assertEquals(R.string.pay_basic, builtInNameRes(line("BASIC", "معاش اساسی")))
assertEquals(R.string.pay_absence, builtInNameRes(line("LOP", "کسر غیرحاضری")))
assertEquals(R.string.pay_income_tax, builtInNameRes(line("TAX", "مالیهٔ معاش")))
}

@Test
fun companyComponentsKeepTheirName() {
assertNull(builtInNameRes(line("TRANSPORT", "کمک ترانسپورت")))
}
}
Loading